home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / magazi~1 / 441 / microch2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-12  |  84.9 KB  |  3,029 lines

  1. /***************************************************************
  2. *                       MICROCHECK ST                          *
  3. *                     by Clayton Walnum                        *
  4. *                                                              *
  5. *                  Copyright 1989 by ST-LOG                    *
  6. *                   Developed with Laser C                     *
  7. *                                                              *
  8. *                   Maintenance history:                       *
  9. *   7/13/89 -- Fixed divide-by-zero error in calc_vslid().     *
  10. *   9/13/89 -- Deleted obsolete "mnth" code from open_acct().  *
  11. *              Changed read in open_acct() to read only 16     *
  12. *                bytes into CHKCITY field, rather than 26.     *
  13. ***************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <osbind.h>
  17. #include <gemdefs.h>
  18. #include <obdefs.h>
  19. #include <fcntl.h>
  20. #include "microchk.h"
  21.  
  22. #define WA_UPPAGE    0
  23. #define WA_DNPAGE    1
  24. #define WA_UPLINE    2
  25. #define WA_DNLINE    3
  26. #define WA_LFPAGE    4
  27. #define WA_RTPAGE    5
  28. #define BOLD         1
  29. #define LIGHT        2
  30. #define TRUE         1
  31. #define FALSE        0
  32. #define YES          1
  33. #define NO           2
  34. #define LEFT_BUTTON  0x0001
  35. #define BUTTON_DOWN  0x0001
  36. #define NUM_CLICKS   2
  37. #define PARTS        NAME|INFO|UPARROW|DNARROW|VSLIDE|FULLER|CLOSER|HSLIDE
  38. #define NUM_COLUMNS  93
  39. #define MED          1
  40. #define MATCH        0
  41. #define REC_LENGTH   117
  42. #define FROM_BEG     0
  43. #define FROM_CUR_POS 1
  44. #define FAILED       (-1)
  45. #define DFLT_DRV     0
  46. #define VISIBLE      1
  47. #define MEDIUM       1
  48. #define HIGH         2
  49. #define CHAR_AVAIL   -1
  50. #define CONSOLE      2
  51. #define ESCAPE       27
  52. #define CNTL_A       0x1e01
  53. #define CNTL_B       0x3002
  54. #define CNTL_C       0x2e03
  55. #define CNTL_D       0x2004
  56. #define CNTL_E       0x1205
  57. #define CNTL_G       0x2207
  58. #define CNTL_I       0x1709
  59. #define CNTL_M       0x320d
  60. #define CNTL_N       0x310e
  61. #define CNTL_O       0x180f
  62. #define CNTL_P       0x1910
  63. #define CNTL_Q       0x1011
  64. #define CNTL_R       0x1312
  65. #define CNTL_S       0x1f13
  66. #define CNTL_W       0x1117
  67. #define CNTL_Y       0x1519
  68.  
  69. int work_in[11], work_out[57], contrl[12],
  70.     intin[128], ptsin[128], intout[128], ptsout[128];
  71.  
  72. int msg_buf[8];
  73.  
  74. long pwrs[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 };
  75.  
  76. int handle, dum, file, key,
  77.     fullx, fully, fullw, fullh, wrkx, wrky, wrkw, wrkh, 
  78.     w_h1, w_h2, res, full, num_trans, charw, charh, curchknum,
  79.     num_deps, num_chks, loaded, all_done, mouse_x, mouse_y,
  80.     num_clicks, edit_top, left, start_mnth, end_mnth, mnth, srch_trans,
  81.     start_num, end_num, cur_count, cur_top, search, saved, canceling,
  82.     month, full_draw, oldcolr;
  83.  
  84. int zero = 0;
  85.  
  86. char filename[64], chkname[30], chkstreet[30], chkcity[50],
  87.      date_but[10], bal_but[10], trans_but[4],
  88.      check_but[4], dep_but[4], mnth_but[10], acct_name[64],
  89.      monthfile[64], cur_chk_num[6], cur_date[7], future_use[40],
  90.      cancmnth[5], chtot[20], dptot[20], chcnt[10], dpcnt[10];
  91.  
  92. char windname[64];
  93. char noacct[] = "No account opened";
  94.  
  95. char canc[] = "CANCEL CHECKS";
  96. char newm[] = "  NEW MONTH  ";
  97.  
  98. char *months[] = { "Month 0", "January", "February", "March", "April",
  99.                    "May", "June", "July", "August", "September", "October",
  100.                    "November", "December" };
  101.  
  102. char spaces[] = "                              ";
  103. char infotext[] = "  Number   Amount    Payee                           Memo                            Date";
  104. char *string, *srch_payee, *srch_memo;
  105. char rule[] = "------------------------------------------------------------------------------";
  106.  
  107. long balance, start_amnt, end_amnt;
  108.  
  109. OBJECT *menu_addr, *check_addr, *newacct_addr, *newfile_addr, 
  110.        *newdate_addr, *srchdial_addr, *cancdial_addr, *recndial_addr,
  111.        *rprtdial_addr, *lkmndial_addr, *srtodial_addr;
  112.  
  113. FILE *acctfile, *mfile;
  114.  
  115. char *get_tedinfo_str ();
  116. FILE *opn_nw_auto ();
  117. long str_to_long ();
  118.  
  119. struct check {
  120.    char number[5];
  121.    char payee[31];
  122.    char memo[31];
  123.    char date[9];
  124.    long amount;
  125.    char cancel[2];
  126. };
  127.  
  128. struct check checks[500];
  129. struct check srch_checks[1000];
  130. struct check *cur_chk_strc;
  131.  
  132. TEDINFO *ob_tedinfo;
  133.  
  134.  
  135. main ()
  136. {
  137.    appl_init ();            /* Initialize application.    */
  138.    open_vwork ();           /* Set up workstation.        */
  139.    do_mcheck();             /* Go do MicroCheck.          */
  140.    v_clsvwk (handle);       /* Close virtual workstation. */
  141.    Setcolor ( 2, oldcolr ); /* Reset color register.      */
  142.    appl_exit ();            /* Back to the desktop.       */
  143. }
  144.  
  145.  
  146. do_mcheck()
  147. {
  148.    oldcolr = Setcolor ( 2, -1 );
  149.    Setcolor ( 2, 0x005 );
  150.    if ( (res = Getrez ()) != HIGH && res != MEDIUM )
  151.       form_alert(1,"[0][MicroCheck ST runs|only in high or medium |resolution.][OK]");
  152.    else {
  153.       graf_mouse ( ARROW, &dum );
  154.       strcpy ( acct_name, "NONE" );
  155.       strcpy ( cur_chk_num, "0000" );
  156.       balance = 0;
  157.       month = -1;
  158.       edit_top = cur_top = num_trans = num_chks = num_deps = 0;
  159.       left = saved = TRUE;
  160.       search = canceling = full_draw = FALSE;
  161.       cur_chk_strc = checks;
  162.       get_date ();
  163.  
  164.       if ( !rsrc_load ( "\MICROCHK.RSC" ) )
  165.          form_alert ( 1, "[1][MICROCHK.RSC missing!][Okay]" );
  166.       else {
  167.          rsrc_gaddr ( R_TREE, MENUBAR, &menu_addr );
  168.          rsrc_gaddr ( R_TREE, CHEKDIAL, &check_addr );
  169.          rsrc_gaddr ( R_TREE, NEWADIAL, &newacct_addr );
  170.          rsrc_gaddr ( R_TREE, FILEDIAL, &newfile_addr );
  171.          rsrc_gaddr ( R_TREE, DATEDIAL, &newdate_addr );
  172.          rsrc_gaddr ( R_TREE, SRCHDIAL, &srchdial_addr );
  173.          rsrc_gaddr ( R_TREE, CANCDIAL, &cancdial_addr );
  174.          rsrc_gaddr ( R_TREE, RECNDIAL, &recndial_addr );
  175.          rsrc_gaddr ( R_TREE, RPRTDIAL, &rprtdial_addr );
  176.          rsrc_gaddr ( R_TREE, LKMNDIAL, &lkmndial_addr );
  177.          rsrc_gaddr ( R_TREE, SRTODIAL, &srtodial_addr );
  178.          menu_bar ( menu_addr, TRUE );
  179.          set_menu_entries ();
  180.          wind_get ( 0, WF_WORKXYWH, &fullx, &fully, &fullw, &fullh );
  181.          w_h1 = wind_create ( 0, fullx, fully, fullw, fullh );
  182.          w_h2 = wind_create ( PARTS, fullx, fully, fullw, fullh );
  183.          wind_set ( w_h2, WF_NAME, noacct, 0, 0 );
  184.          wind_set ( w_h2, WF_INFO, infotext, 0, 0 );
  185.          wind_open ( w_h1, fullx, fully, fullw, fullh );
  186.          wind_open ( w_h2, fullx, fully, fullw, 316 - 162*(res==MED) );
  187.          calc_vslid ( 1 );
  188.          calc_hslid ( NUM_COLUMNS );
  189.          full = FALSE;
  190.          loaded = FALSE;
  191.  
  192.          get_event ();
  193.  
  194.          menu_bar ( menu_addr, FALSE );
  195.          wind_close ( w_h2 );
  196.          wind_delete ( w_h2 );
  197.          wind_close ( w_h1 );
  198.          wind_delete ( w_h1 );
  199.          rsrc_free ();
  200.       }
  201.    }
  202. }
  203.  
  204.  
  205. get_event ()
  206. {
  207.    int h, event;
  208.  
  209.    all_done = FALSE;
  210.  
  211.    while ( !all_done ) {
  212.       event = evnt_multi ( MU_KEYBD|MU_MESAG|MU_BUTTON, NUM_CLICKS, 
  213.                          LEFT_BUTTON, BUTTON_DOWN,
  214.                          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, msg_buf, 0, 0,
  215.                          &mouse_x, &mouse_y, &dum, &dum, &key, &num_clicks );
  216.  
  217.       if ( event & MU_KEYBD )
  218.          handle_keys ();
  219.  
  220.       if ( event & MU_MESAG )
  221.          handle_messages ();
  222.  
  223.       if ( event & MU_BUTTON )
  224.          handle_button ();
  225.    }
  226. }
  227.  
  228.  
  229. handle_keys ()
  230. {
  231.    int button;
  232.  
  233.    if ( loaded && !search && !canceling )
  234.       switch ( key ) {
  235.  
  236.          case CNTL_A:
  237.             menu_tnormal ( menu_addr, CHECKS, FALSE );
  238.             do_auto ();
  239.             menu_tnormal ( menu_addr, CHECKS, TRUE );
  240.             break;
  241.  
  242.          case CNTL_E:
  243.             menu_tnormal ( menu_addr, CHECKS, FALSE );
  244.             do_enter ();
  245.             menu_tnormal ( menu_addr, CHECKS, TRUE );
  246.             break;
  247.  
  248.          case CNTL_M:
  249.             menu_tnormal ( menu_addr, FILEBAR, FALSE );
  250.             do_new_mnth ();
  251.             menu_tnormal ( menu_addr, FILEBAR, TRUE );
  252.             break;
  253.  
  254.          case CNTL_P:
  255.             menu_tnormal ( menu_addr, CHECKS, FALSE );
  256.             do_check_canc ();
  257.             menu_tnormal ( menu_addr, CHECKS, TRUE );
  258.             break;
  259.  
  260.          case CNTL_R:
  261.             menu_tnormal ( menu_addr, CHECKS, FALSE );
  262.             do_reconcil ();
  263.             menu_tnormal ( menu_addr, CHECKS, TRUE );
  264.             break;
  265.       }
  266.  
  267.    if ( !loaded )
  268.       switch ( key ) {
  269.  
  270.          case CNTL_N:
  271.             menu_tnormal ( menu_addr, FILEBAR, FALSE );
  272.             do_newacct ();
  273.             menu_tnormal ( menu_addr, FILEBAR, TRUE );
  274.             break;
  275.  
  276.          case CNTL_O:
  277.             menu_tnormal ( menu_addr, FILEBAR, FALSE );
  278.             button = get_acct ();
  279.             if ( button )
  280.                open_acct ( filename );
  281.             menu_tnormal ( menu_addr, FILEBAR, TRUE );
  282.             break;
  283.  
  284.          case CNTL_Y:
  285.             menu_tnormal ( menu_addr, UTILITY, FALSE );
  286.             do_new_year ();
  287.             menu_tnormal ( menu_addr, UTILITY, TRUE );
  288.             break;
  289.  
  290.          case CNTL_I:
  291.             menu_tnormal ( menu_addr, UTILITY, FALSE );
  292.             do_import ();
  293.             menu_tnormal ( menu_addr, UTILITY, TRUE );
  294.             break;
  295.       }
  296.  
  297.    switch ( key ) {
  298.  
  299.       case CNTL_Q:
  300.          menu_tnormal ( menu_addr, FILEBAR, FALSE );
  301.          do_quit ();
  302.          menu_tnormal ( menu_addr, FILEBAR, TRUE );
  303.          break;
  304.  
  305.       case CNTL_S:
  306.         if ( loaded && !canceling ) {
  307.            menu_tnormal ( menu_addr, CHECKS, FALSE );
  308.            do_search ();
  309.            menu_tnormal ( menu_addr, CHECKS, TRUE );
  310.         }
  311.         break;
  312.  
  313.       case CNTL_C:
  314.          if ( loaded ) {
  315.             menu_tnormal ( menu_addr, FILEBAR, FALSE );
  316.             do_wind_close ();
  317.             menu_tnormal ( menu_addr, FILEBAR, TRUE );
  318.          }
  319.          break;
  320.  
  321.       case CNTL_D:
  322.          menu_tnormal ( menu_addr, UTILITY, FALSE );
  323.          get_new_date ();
  324.          menu_tnormal ( menu_addr, UTILITY, TRUE );
  325.          break;
  326.  
  327.       case CNTL_W:
  328.          if ( loaded ) {
  329.             menu_tnormal ( menu_addr, PRINT, FALSE );
  330.             print_wind ();
  331.             menu_tnormal ( menu_addr, PRINT, TRUE );
  332.          }
  333.          break;
  334.  
  335.       case CNTL_G:
  336.          if ( loaded ) {
  337.             menu_tnormal ( menu_addr, PRINT, FALSE );
  338.             print_reg ();
  339.             menu_tnormal ( menu_addr, PRINT, TRUE );
  340.          }
  341.          break;
  342.  
  343.    }
  344. }
  345.  
  346.  
  347. handle_messages ()
  348. {
  349.    switch ( msg_buf[0] ) {
  350.  
  351.       case MN_SELECTED:
  352.          do_menu ();
  353.          break;
  354.  
  355.       case WM_REDRAW:
  356.          do_redraw ( (GRECT *) &msg_buf[4] );
  357.          break;
  358.  
  359.       case WM_FULLED:
  360.          do_full ();
  361.          break;
  362.  
  363.       case WM_ARROWED:
  364.          do_arrow ();
  365.          break;
  366.  
  367.       case WM_VSLID:
  368.          do_vslide ();
  369.          break;
  370.  
  371.       case WM_HSLID:
  372.          do_hslide ();
  373.          break;
  374.  
  375.       case WM_CLOSED:
  376.          do_wind_close ();
  377.          break;
  378.    }     
  379. }
  380.  
  381.  
  382. do_menu ()
  383. {
  384.    int button;
  385.  
  386.    switch ( msg_buf[3] ) {
  387.  
  388.       case DESK:
  389.          form_alert(1,"[0][     MicroCheck ST|   by Clayton Walnum|       (9/13/89)|  |Copyright 1989 by ST-Log  ][CONTINUE]");
  390.          break;
  391.  
  392.       case FILEBAR:
  393.          switch ( msg_buf[4] ) {
  394.  
  395.             case NEWACCNT:
  396.                do_newacct ();
  397.                break;
  398.  
  399.             case OPENMBR:
  400.                button = get_acct ();
  401.                if ( button )
  402.                   open_acct ( filename );
  403.                break;
  404.  
  405.             case CLOSEMBR:
  406.                do_wind_close ();
  407.                break;
  408.  
  409.             case NEWMNTH:
  410.                do_new_mnth ();
  411.                break;
  412.  
  413.             case QUIT:
  414.                do_quit ();
  415.                break;
  416.         }
  417.         break;
  418.  
  419.      case CHECKS:
  420.         switch ( msg_buf[4] ) {
  421.  
  422.            case ENTER:
  423.               do_enter ();
  424.               break;
  425.  
  426.            case SEARCH:
  427.               do_search ();
  428.               break;
  429.  
  430.            case CHKCAN:
  431.               do_check_canc ();
  432.               break;
  433.  
  434.            case RECONCIL:
  435.               do_reconcil ();
  436.               break;
  437.  
  438.            case CHKAUTO:
  439.               do_auto ();
  440.               break;
  441.         }
  442.         break;
  443.  
  444.      case PRINT:
  445.         switch ( msg_buf[4] ) {
  446.  
  447.            case PRNTWIND:
  448.               print_wind ();
  449.               break;
  450.  
  451.            case PRNTREG:
  452.               print_reg ();
  453.               break;
  454.         }
  455.  
  456.      case UTILITY:
  457.         switch ( msg_buf[4] ) {
  458.  
  459.            case NEWYEAR:
  460.               do_new_year ();
  461.               break;
  462.  
  463.            case NEWDATE:
  464.               get_new_date ();
  465.               break;
  466.  
  467.            case IMPORT:
  468.               do_import ();
  469.               break;
  470.  
  471.         }
  472.         break;
  473.    }
  474.    menu_tnormal ( menu_addr, msg_buf[3], TRUE );
  475. }
  476.  
  477.  
  478. do_new_mnth ()
  479. {
  480.    int choice;
  481.  
  482.    cancdial_addr[CANCSTRG].ob_spec = newm;
  483.    choice = get_month ();
  484.    if ( choice == CANCOK ) {
  485.       if ( !saved )
  486.          save_month ( monthfile );
  487.       open_new_month ();
  488.    }
  489. }
  490.  
  491.  
  492. do_wind_close ()
  493. {
  494.    int button;
  495.    GRECT r;
  496.  
  497.    wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  498.    wind_update ( BEG_UPDATE );
  499.    if ( search ) {
  500.       search = FALSE;
  501.       cur_top = edit_top;
  502.       cur_count = num_trans;
  503.       cur_chk_strc = checks;
  504.       srch_trans = 0;
  505.       set_menu_entries ();
  506.       strcpy ( windname, acct_name );
  507.       strcpy ( &windname[strlen(windname)], ": Edit mode" );
  508.       wind_set ( w_h2, WF_NAME, windname, 0, 0 );
  509.       draw_interior ( r );
  510.    }
  511.    else if ( canceling ) {
  512.       if ( !saved )
  513.          save_month ( monthfile );
  514.       canceling = FALSE;
  515.       strcpy ( windname, acct_name );
  516.       strcpy ( &windname[strlen(windname)], ": Edit mode" );
  517.       wind_set ( w_h2, WF_NAME, windname, 0, 0 );
  518.       draw_interior ( r );
  519.       set_menu_entries ();
  520.    }
  521.    else if ( loaded ) {
  522.       button = form_alert ( 1, "[2][Do you want to close|this account?][YES|NO]");
  523.       if ( button == YES ) {
  524.          do_save ();
  525.          draw_rec ( r, 2, 8, WHITE );
  526.          set_menu_entries ();
  527.          wind_set ( w_h2, WF_NAME, noacct, 0, 0 );
  528.       }
  529.    }
  530.    wind_update ( END_UPDATE );
  531. }
  532.  
  533.  
  534. handle_button ()
  535. {
  536.    wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh );
  537.    if ( mouse_y > wrky && mouse_y < wrky + cur_count * charh + 4 
  538.            && mouse_y < wrky + wrkh && mouse_x > wrkx 
  539.            && mouse_x < wrkx+wrkw && num_clicks == 1 )
  540.       if ( !search && !canceling )
  541.          edit ();
  542.       else if ( canceling )
  543.          canc_chk ();
  544. }
  545.  
  546.  
  547. canc_chk ()
  548. {
  549.    int line, index;
  550.  
  551.    graf_mouse ( M_OFF, 0L );
  552.    line = ( mouse_y - wrky - 4 ) / charh;
  553.    index = cur_top + line;
  554.    if ( strcmp ( checks[index].cancel, "*" ) == MATCH )
  555.       strcpy ( checks[index].cancel, " " );
  556.    else
  557.       strcpy ( checks[index].cancel, "*" );
  558.    prnt_chk_wnd ( index, wrky + charh + line * charh );
  559.    saved = FALSE;
  560.    graf_mouse ( M_ON, 0L );
  561. }
  562.  
  563.  
  564. do_save ()
  565. {
  566.    char a[20];
  567.    int len;
  568.  
  569.    if ( !saved ) {
  570.       save_month ( monthfile );
  571.       clear_window ();
  572.    }
  573.    if ( ( mfile = fopen ( filename, "br+" )) == NULL )
  574.       form_alert ( 1, 
  575.              "[1][Error opening .MCK file!|Cannot update balance.][OK]" );
  576.    else {
  577.       fseek ( mfile, 91L, FROM_BEG );
  578.       fwrite ( &balance, 4, 1, mfile );
  579.       if ( fclose ( mfile ) != 0 )
  580.          form_alert ( 1, "[1][File close error!][OK]");
  581.    }
  582.    if ( !search ) {
  583.       loaded = FALSE;
  584.       num_trans = num_chks = num_deps = cur_count = 0;
  585.       balance = 0;
  586.       month = -1;
  587.       strcpy ( acct_name, "NONE" );
  588.       if ( !full )
  589.          draw_buttons ();
  590.       set_menu_entries ();
  591.    }
  592. }
  593.  
  594.  
  595. save_month ( file )
  596. char *file;
  597. {
  598.    char newmfile[64];
  599.    int x;
  600.  
  601.    strcpy ( newmfile, file );
  602.    strcpy ( &newmfile[strlen(newmfile)-3], "BAK" );
  603.    Fdelete ( newmfile );
  604.    if ( Frename ( 0, file, newmfile ) == FAILED )
  605.       form_alert ( 1, "[1][Error creating .BAK file!][OK]" );
  606.    if ( ( mfile = fopen ( file, "bw" )) == 0 ) {
  607.       form_alert ( 1, "[1][Disk Error!|Cannot save file.][CONTINUE]" );
  608.       Frename ( 0, newmfile, file );
  609.    }
  610.    else {
  611.       fwrite ( &num_trans, 2, 1, mfile );
  612.       for ( x=0; x<num_trans; ++x )
  613.          save_check ( x, mfile );
  614.       if ( fclose ( mfile ) != 0 )
  615.          form_alert ( 1, "[1][File close error!][OKAY]");
  616.       else
  617.          saved = TRUE;
  618.       if ( ( mfile = fopen ( filename, "br+" )) == NULL )
  619.          form_alert ( 1, 
  620.                 "[1][Error opening .MCK file!|Cannot update balance.][OK]" );
  621.       else {
  622.          fseek ( mfile, 91L, FROM_BEG );
  623.          fwrite ( &balance, 4, 1, mfile );
  624.          if ( fclose ( mfile ) != 0 )
  625.             form_alert ( 1, "[1][File close error!][OK]");
  626.       }
  627.    }
  628. }
  629.  
  630.  
  631. open_month ( file, mnth )
  632. char *file, *mnth;
  633. {
  634.    int x, len, button, do_it, trans_cnt, old_dep_cnt, old_chk_cnt;
  635.    char a[20], new_mfile[64];
  636.  
  637.    saved = TRUE;
  638.    old_dep_cnt = num_deps;
  639.    old_chk_cnt = num_chks;
  640.    num_chks = num_deps = 0;
  641.    strcpy ( new_mfile, filename );
  642.    strcpy ( &new_mfile[strlen(new_mfile)-4], mnth );
  643.    strcpy ( &new_mfile[strlen(new_mfile)], ".DAT" );
  644.    if ( ( mfile = fopen ( new_mfile, "br" )) == 0 )
  645.       form_alert ( 1, "[1][Can't open the file][CONTINUE]" );
  646.    else {
  647.       do_it = TRUE;
  648.       fread ( &trans_cnt, 2, 1, mfile );
  649.       if ( trans_cnt == 0 ) {
  650.          button = form_alert ( 1, "[2][The data file for|this month is empty.|Do you want to start|a new month?][YES|NO]" );
  651.          if ( button == YES ) {
  652.             num_trans = load_auto ();
  653.          }
  654.          else {
  655.             do_it = FALSE;
  656.             num_chks = old_chk_cnt;
  657.             num_deps = old_dep_cnt;
  658.          }
  659.       }
  660.       else
  661.          num_trans = trans_cnt;
  662.       if ( do_it ) {
  663.          clear_window ();
  664.          loaded = TRUE;
  665.          if ( balance < 0 && balance > (-100) )
  666.             sprintf ( bal_but, "$-%ld.%02ld", balance/100,labs(balance%100) );
  667.          else
  668.             sprintf ( bal_but, "$%ld.%02ld", balance/100,labs(balance%100) );
  669.          strcpy ( monthfile, new_mfile );
  670.          strcpy ( acct_name, file );
  671.          month = atoi ( mnth );
  672.          x = 0;
  673.          while ( x < trans_cnt ) {
  674.             read_check ( x, mfile );
  675.             if ( strcmp ( checks[x].number, "9999" ) == MATCH )
  676.                num_deps += 1;
  677.             else
  678.                num_chks += 1; 
  679.             ++x;
  680.          }
  681.          if ( x > 0 ) {
  682.             strcpy ( cur_chk_num, checks[x-1].number );
  683.             curchknum = atoi ( cur_chk_num );
  684.             if ( strcmp ( cur_chk_num, "9999" ) != MATCH ) {
  685.                curchknum += 1;
  686.                sprintf ( a, "%d", curchknum );
  687.                len = strlen ( a );
  688.                strcpy ( &cur_chk_num[4-len], a );
  689.             }
  690.          }
  691.          cur_top = edit_top = 0;
  692.          cur_count = num_trans;
  693.          cur_chk_strc = checks;
  694.          strcpy ( windname, acct_name );
  695.          strcpy ( &windname[strlen(windname)], ": Edit mode" );
  696.          wind_set ( w_h2, WF_NAME, windname, 0, 0 );
  697.          full_draw = TRUE;
  698.          if ( fclose ( mfile ) != 0 )
  699.             form_alert ( 1, "[1][File close error!][OKAY]");
  700.       }
  701.    }
  702. }
  703.  
  704.  
  705. do_arrow ()
  706. {
  707.    switch ( msg_buf[4] ) {
  708.  
  709.    case WA_UPPAGE:
  710.       do_uppage ();
  711.       break;
  712.  
  713.    case WA_DNPAGE:
  714.       do_dnpage ();
  715.       break;
  716.  
  717.    case WA_UPLINE:
  718.       do_upline ();
  719.       break;
  720.  
  721.    case WA_DNLINE:
  722.       do_dnline ();
  723.       break;
  724.  
  725.    case WA_LFPAGE:
  726.    case WA_RTPAGE:
  727.       do_hslide ();
  728.       break;
  729.  
  730.    }
  731. }
  732.  
  733.  
  734. do_vslide ()
  735. {
  736.    GRECT r;
  737.    int lines_avail;
  738.  
  739.    wind_get ( w_h2, WF_VSLIDE, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  740.    if ( r.g_x != msg_buf[4] ) {
  741.       wind_update ( BEG_UPDATE );
  742.       wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  743.       lines_avail = r.g_h / charh;
  744.       cur_top = (long)msg_buf[4]*((long)cur_count-(long)lines_avail)/1000L;
  745.       wind_set ( w_h2, WF_VSLIDE, msg_buf[4], 0, 0, 0 );
  746.       draw_interior ( r );
  747.       wind_update ( END_UPDATE );
  748.    }
  749. }
  750.  
  751.  
  752. do_hslide ()
  753. {
  754.    GRECT r;
  755.  
  756.    wind_get ( w_h2, WF_HSLIDE, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  757.    if ( r.g_x != msg_buf[4] ) {
  758.       wind_update ( BEG_UPDATE );
  759.       wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  760.       left = !left;
  761.       if ( left ) {
  762.          wind_set ( w_h2, WF_INFO, infotext, 0, 0 );
  763.          wind_set ( w_h2, WF_HSLIDE, 0, 0, 0, 0 );
  764.       }
  765.       else {
  766.          wind_set ( w_h2, WF_INFO, &infotext[20], 0, 0 );
  767.          wind_set ( w_h2, WF_HSLIDE, 166, 0, 0, 0 );
  768.       }
  769.       draw_interior ( r );
  770.       wind_update ( END_UPDATE );
  771.    }
  772. }
  773.  
  774.  
  775. do_uppage ()
  776. {
  777.     GRECT r;
  778.     int lines_avail;
  779.  
  780.    wind_update ( BEG_UPDATE );
  781.     wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  782.     lines_avail = r.g_h / charh;
  783.     cur_top -= lines_avail;
  784.     if ( cur_top < 0 )
  785.       cur_top = 0;
  786.    wind_update ( END_UPDATE );
  787.     draw_interior ( r );
  788. }
  789.  
  790.  
  791. do_dnpage ()
  792. {
  793.    GRECT r;
  794.    int lines_avail;
  795.  
  796.    wind_update ( BEG_UPDATE );
  797.    wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  798.    lines_avail = r.g_h / charh;
  799.    cur_top += lines_avail;
  800.    if ( cur_top > cur_count - lines_avail )
  801.       cur_top = cur_count - lines_avail;
  802.    draw_interior ( r );
  803.    wind_update ( END_UPDATE );
  804. }
  805.  
  806.    
  807. do_upline ()
  808. {
  809.    MFDB s, d;
  810.    GRECT r;
  811.    int pxy[8];
  812.  
  813.    if ( cur_top != 0 ) {
  814.       wind_update ( BEG_UPDATE );
  815.       cur_top -= 1;
  816.       wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  817.       set_clip ( TRUE, r );
  818.       graf_mouse ( M_OFF, 0L );
  819.       s.fd_addr = 0L;
  820.       d.fd_addr = 0L;
  821.       pxy[0] = r.g_x; 
  822.       pxy[1] = r.g_y + 2; 
  823.       pxy[2] = r.g_x + r.g_w; 
  824.       pxy[3] = r.g_y + r.g_h - charh - 2;
  825.       pxy[4] = r.g_x;
  826.       pxy[5] = r.g_y + charh + 2; 
  827.       pxy[6] = r.g_x + r.g_w; 
  828.       pxy[7] = r.g_y + r.g_h - 2;
  829.       vro_cpyfm ( handle, S_ONLY, pxy, &s, &d );
  830.       prnt_chk_wnd ( cur_top, r.g_y + charh );
  831.       set_clip ( FALSE, r );
  832.       calc_vslid ( cur_count );
  833.       wind_update ( END_UPDATE );
  834.       graf_mouse ( M_ON, 0L );
  835.    }
  836. }
  837.  
  838.  
  839. do_dnline ()
  840. {
  841.    MFDB s, d;
  842.    GRECT r;
  843.    int pxy[8];
  844.    int lines_avail, index;
  845.  
  846.    wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  847.    lines_avail = r.g_h / charh;
  848.    if ( (cur_top + lines_avail) < cur_count ) {
  849.       wind_update ( BEG_UPDATE );
  850.       cur_top += 1;
  851.       index = cur_top + lines_avail - 1;
  852.       set_clip ( TRUE, r );
  853.       graf_mouse ( M_OFF, 0L );
  854.       s.fd_addr = 0L;
  855.       d.fd_addr = 0L;
  856.       pxy[0] = r.g_x; 
  857.       pxy[1] = r.g_y + charh + 3 - 1*(res==MED); 
  858.       pxy[2] = r.g_x + r.g_w; 
  859.       pxy[3] = r.g_y + r.g_h - 1;
  860.       pxy[4] = r.g_x;
  861.       pxy[5] = r.g_y + 3 -1*(res==MED); 
  862.       pxy[6] = r.g_x + r.g_w; 
  863.       pxy[7] = r.g_y + r.g_h - charh - 1;
  864.       vro_cpyfm ( handle, S_ONLY, pxy, &s, &d );
  865.       prnt_chk_wnd ( index, r.g_y + lines_avail * charh );
  866.       set_clip ( FALSE, r );
  867.       calc_vslid ( cur_count );
  868.       wind_update ( END_UPDATE );
  869.       graf_mouse ( M_ON, 0L );
  870.    }
  871. }
  872.  
  873.  
  874. do_check_canc ()
  875. {
  876.    int choice, okay;
  877.  
  878.    cancdial_addr[CANCSTRG].ob_spec = canc;
  879.    choice = get_month ();
  880.  
  881.    if ( choice == CANCOK ) {
  882.       if ( !saved ) {
  883.          save_month ( monthfile );
  884.          clear_window ();
  885.       }
  886.       set_canc_menu ();
  887.       cur_chk_strc = checks;
  888.       cur_top = 0;
  889.       open_new_month ();
  890.       canceling = TRUE;
  891.       strcpy ( windname, acct_name );
  892.       strcpy ( &windname[strlen(windname)], ": Cancel Mode" );
  893.       wind_set ( w_h2, WF_NAME, windname, 0, 0 );
  894.    }
  895.    else
  896.       canceling = FALSE;
  897. }
  898.  
  899.  
  900. clear_cancdial ()
  901. {
  902.    int x;
  903.  
  904.    for ( x=JAN; x<=MZERO; cancdial_addr[x++].ob_state = NORMAL ) ;
  905.    if ( month != -1 )
  906.       if ( month == 0 )
  907.          cancdial_addr[MZERO].ob_state = SELECTED;
  908.       else
  909.          cancdial_addr[month+JAN-1].ob_state = SELECTED;
  910. }
  911.  
  912.  
  913. open_new_month ()
  914. {
  915.    int mnth, x;
  916.  
  917.    for ( x=JAN; x<=MZERO; ++x )
  918.       if ( cancdial_addr[x].ob_state == SELECTED )
  919.          if ( x == MZERO )
  920.             mnth = 0;
  921.          else
  922.             mnth = x-JAN+1;
  923.    sprintf ( cancmnth, "%d", mnth );
  924.    open_month ( acct_name, cancmnth );
  925. }
  926.  
  927.  
  928. do_reconcil ()
  929. {
  930.    int choice, okay;
  931.    int dial_x, dial_y, dial_w, dial_h;
  932.  
  933.    if ( !saved )
  934.       save_month ( monthfile );
  935.  
  936.    string = get_tedinfo_str ( recndial_addr, ENDBAL );
  937.    string[0] = '@';
  938.    form_center ( recndial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  939.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  940.    objc_draw ( recndial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  941.    okay = TRUE;
  942.  
  943.    do {
  944.       choice = form_do ( recndial_addr, ENDBAL );
  945.       recndial_addr[choice].ob_state = SHADOWED;
  946.  
  947.       if ( choice == ENDBOK ) {
  948.          okay = val_bal ();
  949.          if ( okay )
  950.             rcncl ();
  951.       }
  952.    }
  953.    while ( okay == FALSE && choice == ENDBOK );
  954.  
  955.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  956. }
  957.  
  958.  
  959. val_bal ()
  960. {
  961.    int okay;
  962.  
  963.    okay = TRUE;
  964.    string = get_tedinfo_str ( recndial_addr, ENDBAL );
  965.    if ( string[0] == '@' | strlen (string) == 0 ) {
  966.       form_alert ( 1, 
  967.                  "[1][You must provide your|account's ending balance][OK]" );
  968.       okay = FALSE;
  969.    }
  970.    return ( okay );
  971. }
  972.  
  973.  
  974. rcncl ()
  975. {
  976.    int x, m, chkcnt, depcnt, trans;
  977.    int dial_x, dial_y, dial_w, dial_h;
  978.    char s[20];
  979.    struct check tmpchk;
  980.    long endbal, deptot, chktot;
  981.  
  982.    chktot = deptot = 0;
  983.    chkcnt = depcnt = 0;
  984.    string = get_tedinfo_str ( recndial_addr, ENDBAL );
  985.    no_decimal ( string );
  986.    endbal = str_to_long ( string );
  987.    form_center ( lkmndial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  988.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  989.    string = get_tedinfo_str ( lkmndial_addr, SCANMNTH );
  990.    strcpy ( string, "         " );
  991.    objc_draw ( lkmndial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  992.    for ( x=0; x<13; ++x ) {
  993.       strcpy ( s, filename );
  994.       sprintf ( &s[strlen(s)-4], "%d", x );
  995.       strcpy ( &s[strlen(s)], ".DAT" );
  996.       if ( ( mfile = fopen ( s, "br" ) ) == 0 )
  997.          form_alert ( 1, 
  998.                    "[1][Cannot open file!|Reconciliation abandoned.][OK]" );
  999.       else {
  1000.          strcpy ( string, months[x] );
  1001.          objc_draw ( lkmndial_addr, SCANMNTH, 8, 
  1002.                      dial_x, dial_y, dial_w, dial_h );
  1003.          fread ( &trans, 2, 1, mfile );
  1004.          for ( m=0; m<trans; ++m ) {
  1005.             fread ( tmpchk.number, 1, 4, mfile );
  1006.             fread ( tmpchk.payee, 1, 30, mfile );
  1007.             fread ( tmpchk.memo, 1, 30, mfile );
  1008.             fread ( tmpchk.date, 1, 8, mfile );
  1009.             fread ( &tmpchk.amount, 4, 1, mfile );
  1010.             fread ( tmpchk.cancel, 1, 1, mfile );
  1011.             fread ( future_use, 1, 40, mfile );
  1012.             if ( tmpchk.cancel[0] == ' ' )
  1013.                if ( strncmp ( tmpchk.number, "9999", 4 ) == MATCH ) {
  1014.                   depcnt += 1;
  1015.                   deptot += tmpchk.amount;
  1016.                }
  1017.                else {
  1018.                   chkcnt += 1;
  1019.                   chktot += tmpchk.amount;
  1020.                }
  1021.          }
  1022.       }
  1023.       if ( fclose ( mfile ) != 0 )
  1024.             form_alert ( 1, "[1][File close error!][OK]");
  1025.    }
  1026.  
  1027.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1028.    show_report ( endbal, chkcnt, chktot, depcnt, deptot );
  1029. }
  1030.  
  1031.  
  1032. show_report ( endbal, chkcnt, chktot, depcnt, deptot )
  1033. long endbal, chktot, deptot;
  1034. int chkcnt, depcnt;
  1035. {
  1036.    long balshld, dif, subtot;
  1037.    int dial_x, dial_y, dial_w, dial_h;
  1038.  
  1039.    subtot = endbal - chktot;
  1040.    balshld = subtot + deptot;
  1041.    dif = balshld - balance;
  1042.    string = rprtdial_addr[RECENDB].ob_spec;
  1043.    if ( endbal < 0 && endbal > (-100) )
  1044.       sprintf ( &string[1], "$-%5ld.%02ld", endbal/100,labs(endbal%100) );
  1045.    else
  1046.       sprintf ( &string[1], "%6ld.%02ld", endbal/100, labs(endbal%100) );
  1047.    string = rprtdial_addr[RECOUTCH].ob_spec;
  1048.    sprintf ( &string[22], "%d", chkcnt );
  1049.    strcpy ( &string[strlen(string)], ")......." );
  1050.    string = rprtdial_addr[RECCHKS].ob_spec;
  1051.    sprintf ( &string[5], "%6ld.%02ld", chktot/100, chktot%100 );
  1052.    string = rprtdial_addr[RECSUBT].ob_spec;
  1053.    if ( subtot < 0 && subtot > (-100) )
  1054.       sprintf ( string, "-%5ld.%02ld", subtot/100, labs(subtot%100) );
  1055.    else
  1056.       sprintf ( string, "%6ld.%02ld", subtot/100, labs(subtot%100) );
  1057.    string = rprtdial_addr[RECOUTDP].ob_spec;
  1058.    sprintf ( &string[24], "%d", depcnt );
  1059.    strcpy ( &string[strlen(string)], ")....." );
  1060.    string = rprtdial_addr[RECDEPS].ob_spec;
  1061.    sprintf ( &string[5], "%6ld.%02ld", deptot/100, deptot%100 );
  1062.    string = rprtdial_addr[RECBALSH].ob_spec;
  1063.    if ( balshld < 0 && balshld > (-100) )
  1064.       sprintf ( string, "-%5ld.%02ld", balshld/100, labs(balshld%100) );
  1065.    else
  1066.       sprintf ( string, "%6ld.%02ld", balshld/100, labs(balshld%100) );
  1067.    string = rprtdial_addr[RECBALIS].ob_spec;
  1068.    if ( balance < 0 && balance > (-100) )
  1069.       sprintf ( string, "-%5ld.%02ld", balance/100, labs(balance%100) );
  1070.    else
  1071.       sprintf ( string, "%6ld.%02ld", balance/100, labs(balance%100) );
  1072.    string = rprtdial_addr[RECDIF].ob_spec;
  1073.    if ( dif < 0 && dif > (-100) )
  1074.       sprintf ( &string[1], "-%5ld.%02ld", dif/100, labs(dif%100) );
  1075.    else
  1076.       sprintf ( &string[1], "%6ld.%02ld", dif/100, labs(dif%100) );
  1077.  
  1078.    form_center ( rprtdial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1079.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1080.    objc_draw ( rprtdial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1081.  
  1082.    form_do ( rprtdial_addr, 0 );
  1083.  
  1084.    rprtdial_addr[RECOK].ob_state = SHADOWED;
  1085.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1086. }
  1087.  
  1088.  
  1089. do_auto ()
  1090. {
  1091.    int choice, len, okay, i;
  1092.    int dial_x, dial_y, dial_w, dial_h;
  1093.  
  1094.    set_auto_chk ();
  1095.    form_center ( check_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1096.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1097.    objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1098.    okay = FALSE;
  1099.  
  1100.    do {
  1101.       choice = form_do ( check_addr, DATE );
  1102.       check_addr[choice].ob_state = SHADOWED;
  1103.  
  1104.       switch ( choice ) {
  1105.  
  1106.          case CHKDONE:
  1107.          case CHKNEXT:
  1108.             okay = validate_check ();
  1109.             if ( okay ) {
  1110.                string = get_tedinfo_str ( check_addr, NUMBER );
  1111.                if ( strcmp ( string, "0000" ) != MATCH &&
  1112.                     strcmp ( string, "9999" ) != MATCH )
  1113.                   strcpy ( string, "0000" );
  1114.                string = get_tedinfo_str ( check_addr, MEMO );
  1115.                strcpy ( string, "AUTO                          " );
  1116.                string = get_tedinfo_str ( check_addr, PAYEE );
  1117.                for ( i=strlen(string); i<30; string[i++]=' ' );
  1118.                save_auto ();
  1119.             }
  1120.             if ( choice != CHKDONE | !okay ) {
  1121.                if ( choice == CHKNEXT )
  1122.                   set_auto_chk ();
  1123.                objc_draw ( check_addr, 0, 8,
  1124.                            dial_x, dial_y, dial_w, dial_h );
  1125.             }
  1126.             break;
  1127.  
  1128.          case CHKCANCL:
  1129.             clear_check ();
  1130.             break;
  1131.       }
  1132.    }
  1133.    while ( (choice != CHKDONE | okay == FALSE) && choice != CHKCANCL );
  1134.  
  1135.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1136. }
  1137.  
  1138.  
  1139. save_auto ()
  1140. {
  1141.    FILE *autofile;
  1142.    char file[64];
  1143.    long amount;
  1144.    int choice, old_count, new_count, file_len;
  1145.  
  1146.    strcpy ( file, filename );
  1147.    strcpy ( &file[strlen(file)-4], ".AUT" );
  1148.    if ( ( autofile = fopen ( file, "br+" ) ) == NULL ) {
  1149.       choice = form_alert ( 1, "[2][Start a new AUTO file?][YES|NO]" );
  1150.       if ( choice = YES )
  1151.          autofile = opn_nw_auto ( file );
  1152.    }
  1153.    if ( autofile != NULL ) {
  1154.       fread ( &old_count, 2, 1, autofile );
  1155.       new_count = old_count + 1;
  1156.       rewind ( autofile );
  1157.       fwrite ( &new_count, 2, 1, autofile );
  1158.       file_len = old_count * REC_LENGTH;
  1159.       fseek ( autofile, (long) file_len, FROM_CUR_POS );
  1160.       string = get_tedinfo_str ( check_addr, NUMBER );
  1161.       fwrite ( string, 1, 4, autofile );
  1162.       string = get_tedinfo_str ( check_addr, PAYEE );
  1163.       fwrite ( string, 1, 30, autofile );
  1164.       fwrite ( "AUTO                          ", 1, 30, autofile );
  1165.       string = get_tedinfo_str ( check_addr, DATE );
  1166.       fwrite ( string, 1, 8, autofile );
  1167.       string = get_tedinfo_str ( check_addr, AMOUNT );
  1168.       no_decimal ( string );
  1169.       amount = str_to_long ( string );
  1170.       fwrite ( &amount, 4, 1, autofile );
  1171.       fwrite ( " ", 1, 1, autofile );
  1172.       fwrite ( "THIS SPACE FOR POSSIBLE FUTURE EXPANSION", 1, 40, autofile );
  1173.       if ( fclose ( autofile ) == FAILED )
  1174.          form_alert ( 1, "[1][File close error!][OKAY]");
  1175.    }
  1176. }
  1177.  
  1178.  
  1179. FILE *opn_nw_auto ( file )
  1180. char *file;
  1181. {
  1182.    FILE *autofile;
  1183.  
  1184.    if ( ( autofile = fopen ( file, "bw" ) ) == NULL )
  1185.       form_alert ( 1, 
  1186.                 "[1][Can't open new AUTO file!|Function aborted.][OK]" );
  1187.    else {
  1188.       fwrite ( &zero, 2, 1, mfile );
  1189.       fclose ( autofile );
  1190.       autofile = fopen ( file, "br+" );
  1191.    }
  1192.    return ( autofile );
  1193. }
  1194.  
  1195.  
  1196. set_auto_chk ()
  1197. {
  1198.    set_chk_strings ();
  1199.    check_addr[CHKNEXT].ob_state = SHADOWED;
  1200.    check_addr[CHKNEXT].ob_flags = SELECTABLE | DEFAULT | TOUCHEXIT;
  1201.    check_addr[CHKDONE].ob_flags = SELECTABLE | TOUCHEXIT;
  1202.    string = get_tedinfo_str ( check_addr, NUMBER );
  1203.    strcpy ( string, "0000" );
  1204.    string = get_tedinfo_str ( check_addr, MEMO );
  1205.    strcpy ( string, "AUTO" );
  1206. }
  1207.  
  1208.  
  1209. load_auto ()
  1210. {
  1211.    char autoname[64];
  1212.    FILE *autofile;
  1213.    int x, count;
  1214.  
  1215.    count = 0;
  1216.    strcpy ( autoname, filename );
  1217.    strcpy ( &autoname[strlen(autoname)-4], ".AUT" );
  1218.    if ( ( autofile = fopen ( autoname, "br" )) != NULL ) {
  1219.       fread ( &count, 2, 1, autofile );
  1220.       x = 0;
  1221.       while ( x < count ) {
  1222.          read_check ( x, autofile );
  1223.          if ( strcmp ( checks[x].number, "9999" ) == MATCH ) {
  1224.             num_deps += 1;
  1225.             balance += checks[x].amount;
  1226.          }
  1227.          else {
  1228.             num_chks += 1; 
  1229.             balance -= checks[x].amount;
  1230.          }
  1231.          ++x;
  1232.       }
  1233.       saved = FALSE;
  1234.       if ( fclose ( autofile ) == FAILED )
  1235.          form_alert ( 1, "[1][Error closing AUTO file!][CONTINUE]" );
  1236.    }
  1237.    return ( count );
  1238. }
  1239.  
  1240.  
  1241. get_month ()
  1242. {
  1243.    int choice;
  1244.    int dial_x, dial_y, dial_w, dial_h;
  1245.  
  1246.    clear_cancdial ();
  1247.    form_center ( cancdial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1248.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1249.    objc_draw ( cancdial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1250.  
  1251.    choice = form_do ( cancdial_addr, 0 );
  1252.    cancdial_addr[choice].ob_state = SHADOWED;
  1253.  
  1254.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1255.    return ( choice );
  1256. }
  1257.  
  1258.  
  1259. get_new_date ()
  1260. {
  1261.    int choice, okay;
  1262.    int dial_x, dial_y, dial_w, dial_h;
  1263.  
  1264.    string = get_tedinfo_str ( newdate_addr, NWDATE );
  1265.    string[0] = 0;
  1266.    form_center ( newdate_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1267.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1268.    objc_draw ( newdate_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1269.  
  1270.    okay = FALSE;
  1271.  
  1272.    do {
  1273.       choice = form_do ( newdate_addr, NWDATE );
  1274.       newdate_addr[choice].ob_state = SHADOWED;
  1275.  
  1276.       switch ( choice ) {
  1277.  
  1278.          case DATEOK:
  1279.             okay = chk_date ();
  1280.             if ( !okay )
  1281.                objc_draw ( newdate_addr, 0, 8, 
  1282.                    dial_x, dial_y, dial_w, dial_h );
  1283.             else {
  1284.                strcpy ( cur_date, string );
  1285.                format_date ( date_but, cur_date );
  1286.                updte_buttons ();
  1287.             }
  1288.             break;
  1289.  
  1290.          case DATECANC:
  1291.             string = get_tedinfo_str ( newdate_addr, NWDATE );
  1292.             string[0] = '@';
  1293.       }
  1294.    }
  1295.    while ( okay == FALSE && choice != DATECANC );
  1296.  
  1297.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1298. }
  1299.  
  1300.  
  1301. chk_date ()
  1302. {
  1303.    int mnth, day, year, okay;
  1304.    char m[3], d[3], y[3];
  1305.  
  1306.    string = get_tedinfo_str ( newdate_addr, NWDATE );
  1307.    if ( strlen ( string ) == 6 ) {
  1308.       strncpy ( m, string, 2 );
  1309.       m[2] = 0;
  1310.       strncpy ( d, &string[2], 2 );
  1311.       d[2] = 0;
  1312.       strncpy ( y, &string[4], 2 );
  1313.       mnth = atoi ( m );
  1314.       day = atoi ( d );
  1315.       year = atoi ( y );
  1316.       if ( mnth < 0 | mnth >12 | day < 1 | day > 31 
  1317.            | year < 0 | year > 99 ) {
  1318.          okay = FALSE;
  1319.       }
  1320.       else
  1321.          okay = TRUE;
  1322.    }
  1323.    else
  1324.       okay = FALSE;
  1325.    if ( !okay ) {
  1326.       form_alert ( 1, "[1][Not a valid date!][CONTINUE]" );
  1327.       string[0] = 0;
  1328.    }
  1329.    return ( okay );
  1330. }
  1331.  
  1332.  
  1333. do_full ()
  1334. {
  1335.    if ( !full )
  1336.       wind_set ( w_h2, WF_CURRXYWH, fullx, fully, fullw, fullh );
  1337.    else
  1338.       wind_set ( w_h2, WF_CURRXYWH, 
  1339.                  fullx, fully, fullw, 316 -162*(res==MED) );
  1340.    calc_vslid ( cur_count );
  1341.    full = !full;
  1342. }
  1343.  
  1344.  
  1345. do_search ()
  1346. {
  1347.    int choice, okay;
  1348.    int dial_x, dial_y, dial_w, dial_h;
  1349.  
  1350.    set_search_menu ();
  1351.    clear_search ();
  1352.    form_center ( srchdial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1353.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1354.  
  1355.    do {
  1356.       objc_draw ( srchdial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1357.       choice = form_do ( srchdial_addr, MNTHFROM );
  1358.       srchdial_addr[choice].ob_state = SHADOWED;
  1359.  
  1360.       switch ( choice ) {
  1361.  
  1362.          case SRCHOK:
  1363.             okay = val_srch ();
  1364.             if ( okay )
  1365.                search_chks ();
  1366.             break;
  1367.  
  1368.          case SRCHCNCL:
  1369.             search = FALSE;
  1370.             set_menu_entries ();
  1371.             break;
  1372.       }
  1373.    }
  1374.    while ( !okay && choice != SRCHCNCL );
  1375.  
  1376.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1377. }
  1378.  
  1379.  
  1380. val_srch ()
  1381. {
  1382.    char f, t;
  1383.    int okay;
  1384.  
  1385.    okay = TRUE;
  1386.    string = get_tedinfo_str ( srchdial_addr, MNTHFROM );
  1387.    f = string[0];
  1388.    string = get_tedinfo_str ( srchdial_addr, MNTHTO );
  1389.    t = string[0];
  1390.    if ( f < '0' | f > '9' | t < '0' | t > '9' ) {
  1391.       form_alert ( 1, "[1][You must enter a|starting and ending month!][CONTINUE]" );
  1392.       okay = FALSE;
  1393.    }
  1394.    return ( okay );
  1395. }
  1396.  
  1397.  
  1398. clear_search ()
  1399. {
  1400.    string = get_tedinfo_str ( srchdial_addr, MNTHFROM );
  1401.    strcpy ( string, "0" );
  1402.    string = get_tedinfo_str ( srchdial_addr, MNTHTO );
  1403.    strcpy ( string, "12" );
  1404.    string = get_tedinfo_str ( srchdial_addr, NUMFROM );
  1405.    strcpy ( string, "0000" );
  1406.    string = get_tedinfo_str ( srchdial_addr, NUMTO );
  1407.    strcpy ( string, "9999" );
  1408.    string = get_tedinfo_str ( srchdial_addr, AMNTFROM );
  1409.    strcpy ( string, "0000000" );
  1410.    string = get_tedinfo_str ( srchdial_addr, AMNTTO );
  1411.    strcpy ( string, "9999999" );
  1412.    string = get_tedinfo_str ( srchdial_addr, PAYEFROM );
  1413.    strcpy ( string, "ANY" );
  1414.    string = get_tedinfo_str ( srchdial_addr, MEMOFROM );
  1415.    strcpy ( string, "ANY" );
  1416. }
  1417.  
  1418.  
  1419. search_chks ()
  1420. {
  1421.    GRECT r;
  1422.    int x, count, i, any_payee, any_memo, trans, c_cnt, d_cnt;
  1423.    char s[64], p[31], m[31];
  1424.    long tot_debit, tot_credit;
  1425.  
  1426.    count = c_cnt = d_cnt = 0;
  1427.    tot_debit = tot_credit = 0;
  1428.    search = TRUE;
  1429.    edit_top = cur_top;
  1430.    cur_chk_strc = srch_checks;
  1431.    any_payee = any_memo = FALSE;
  1432.    srch_trans = 0;
  1433.    get_srch_param ();
  1434.    if ( !saved )
  1435.       do_save ();
  1436.    for ( x=start_mnth; x<=end_mnth && count < 1000; ++x ) {
  1437.       strcpy ( s, filename );
  1438.       sprintf ( &s[strlen(s)-4], "%d", x );
  1439.       strcpy ( &s[strlen(s)], ".DAT" );
  1440.       if ( ( mfile = fopen ( s, "br" ) ) == 0 )
  1441.          form_alert ( 1, 
  1442.                      "[1][Cannot open file!|Search abandoned.][CONTINUE]" );
  1443.       else {
  1444.          fread ( &trans, 2, 1, mfile );
  1445.          srch_trans += trans;
  1446.          i = 0;
  1447.          if ( strcmp ( srch_payee, "ANY" ) == MATCH )
  1448.             any_payee = TRUE;
  1449.          if ( strcmp ( srch_memo, "ANY" ) == MATCH )
  1450.             any_memo = TRUE;
  1451.          while ( i++ < trans && count < 1000 ) {
  1452.             fread ( srch_checks[count].number, 1, 4, mfile );
  1453.             fread ( srch_checks[count].payee, 1, 30, mfile );
  1454.             fread ( srch_checks[count].memo, 1, 30, mfile );
  1455.             fread ( srch_checks[count].date, 1, 8, mfile );
  1456.             fread ( &srch_checks[count].amount, 4, 1, mfile );
  1457.             fread ( srch_checks[count].cancel, 1, 1, mfile );
  1458.             fread ( future_use, 1, 40, mfile );
  1459.             strcpy ( p, srch_checks[count].payee );
  1460.             strcpy ( m, srch_checks[count].memo );
  1461.             if ( any_payee )
  1462.                strcpy ( srch_payee, srch_checks[count].payee );
  1463.             else if ( strlen ( p ) >= strlen ( srch_payee ) )
  1464.                p[ strlen ( srch_payee ) ] = 0;
  1465.             if ( any_memo )
  1466.                strcpy ( srch_memo, srch_checks[count].memo );
  1467.             else if ( strlen ( m ) >= strlen ( srch_memo ) )
  1468.                m[ strlen ( srch_memo ) ] = 0;
  1469.             make_upper_case ( srch_payee );
  1470.             make_upper_case ( srch_memo );
  1471.             make_upper_case ( p );
  1472.             make_upper_case ( m );
  1473.             if ( atoi ( srch_checks[count].number ) >= start_num &&
  1474.                  atoi ( srch_checks[count].number ) <= end_num &&
  1475.                  srch_checks[count].amount >= start_amnt &&
  1476.                  srch_checks[count].amount <= end_amnt &&
  1477.                  ( strcmp ( p, srch_payee ) == MATCH ) &&
  1478.                  ( strcmp ( m, srch_memo ) == MATCH ) ) {
  1479.                ++count;
  1480.                if ( strcmp ( srch_checks[count-1].number, "9999" ) == MATCH ) {
  1481.                   tot_credit += srch_checks[count-1].amount;
  1482.                   ++d_cnt;
  1483.                } 
  1484.                else {
  1485.                   tot_debit += srch_checks[count-1].amount;
  1486.                   ++c_cnt;
  1487.                }
  1488.             }
  1489.               
  1490.          }
  1491.       }
  1492.       if ( count == 1000 )
  1493.          form_alert(1,"[1][You've reached the search|function's 1000 check limit.|All checks that match the|search parameters may not|be shown!][OK]");
  1494.       if ( fclose ( mfile ) != 0 )
  1495.             form_alert ( 1, "[1][File close error!][OKAY]");
  1496.    }
  1497.    cur_top = 0;
  1498.    cur_count = count;
  1499.    strcpy ( windname, acct_name );
  1500.    strcpy ( &windname[strlen(windname)], ": Search mode" );
  1501.    wind_set ( w_h2, WF_NAME, windname, 0, 0 );
  1502.    full_draw = TRUE;
  1503.    sprintf ( chtot, "%6ld.%02ld", tot_debit/100, tot_debit%100 );
  1504.    sprintf ( dptot, "%6ld.%02ld", tot_credit/100, tot_credit%100 );
  1505.    sprintf ( chcnt, "%d", c_cnt );
  1506.    sprintf ( dpcnt, "%d", d_cnt );
  1507.    search_report ();
  1508. }
  1509.  
  1510.  
  1511. search_report ()
  1512. {
  1513.    int dial_x, dial_y, dial_w, dial_h;
  1514.  
  1515.    string = srtodial_addr[DBCNT].ob_spec;
  1516.    strcpy ( string, chcnt );
  1517.    string = srtodial_addr[DBTOT].ob_spec;
  1518.    strcpy ( string, chtot );
  1519.    string = srtodial_addr[CRCNT].ob_spec;
  1520.    strcpy ( string, dpcnt );
  1521.    string = srtodial_addr[CRTOT].ob_spec;
  1522.    strcpy ( string, dptot );
  1523.  
  1524.    form_center ( srtodial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1525.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1526.    objc_draw ( srtodial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1527.  
  1528.    form_do ( srtodial_addr, 0 );
  1529.  
  1530.    srtodial_addr[SRTOOK].ob_state = SHADOWED;
  1531.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1532. }
  1533.  
  1534.  
  1535. get_srch_param ()
  1536. {
  1537.    char s[10];
  1538.  
  1539.    string = get_tedinfo_str ( srchdial_addr, MNTHFROM );
  1540.    start_mnth = atoi ( string );
  1541.    string = get_tedinfo_str ( srchdial_addr, MNTHTO );
  1542.    end_mnth = atoi ( string );
  1543.    string = get_tedinfo_str ( srchdial_addr, NUMFROM );
  1544.    start_num = atoi ( string );
  1545.    string = get_tedinfo_str ( srchdial_addr, NUMTO );
  1546.    end_num = atoi ( string );
  1547.    string = get_tedinfo_str ( srchdial_addr, AMNTFROM );
  1548.    no_decimal ( string );
  1549.    start_amnt = str_to_long ( string );
  1550.    string = get_tedinfo_str ( srchdial_addr, AMNTTO );
  1551.    no_decimal ( string );
  1552.    end_amnt = str_to_long ( string );
  1553.    srch_payee = get_tedinfo_str ( srchdial_addr, PAYEFROM );
  1554.    srch_memo = get_tedinfo_str ( srchdial_addr, MEMOFROM );
  1555. }
  1556.  
  1557.  
  1558. set_menu_entries ()
  1559. {
  1560.    menu_ienable ( menu_addr, CLOSEMBR, loaded );
  1561.    menu_ienable ( menu_addr, OPENMBR, !loaded );
  1562.    menu_ienable ( menu_addr, NEWACCNT, !loaded );
  1563.    menu_ienable ( menu_addr, QUIT, TRUE );
  1564.    menu_ienable ( menu_addr, ENTER, loaded );
  1565.    menu_ienable ( menu_addr, SEARCH, loaded );
  1566.    menu_ienable ( menu_addr, CHKCAN, loaded );
  1567.    menu_ienable ( menu_addr, NEWMNTH, loaded );
  1568.    menu_ienable ( menu_addr, RECONCIL, loaded );
  1569.    menu_ienable ( menu_addr, PRNTWIND, loaded );
  1570.    menu_ienable ( menu_addr, PRNTREG, loaded );
  1571.    menu_ienable ( menu_addr, NEWYEAR, !loaded );
  1572.    menu_ienable ( menu_addr, CHKAUTO, loaded );
  1573.    menu_ienable ( menu_addr, NEWDATE, TRUE );
  1574.    menu_ienable ( menu_addr, IMPORT, !loaded );
  1575. }
  1576.  
  1577.  
  1578. set_search_menu ()
  1579. {
  1580.    menu_ienable ( menu_addr, CLOSEMBR, TRUE );
  1581.    menu_ienable ( menu_addr, OPENMBR, FALSE );
  1582.    menu_ienable ( menu_addr, QUIT, TRUE );
  1583.    menu_ienable ( menu_addr, NEWACCNT, FALSE );
  1584.    menu_ienable ( menu_addr, ENTER, FALSE );
  1585.    menu_ienable ( menu_addr, SEARCH, TRUE );
  1586.    menu_ienable ( menu_addr, CHKCAN, FALSE );
  1587.    menu_ienable ( menu_addr, CHKAUTO, FALSE );
  1588.    menu_ienable ( menu_addr, NEWMNTH, FALSE );
  1589.    menu_ienable ( menu_addr, RECONCIL, FALSE );
  1590.    menu_ienable ( menu_addr, PRNTWIND, TRUE );
  1591.    menu_ienable ( menu_addr, PRNTREG, TRUE );
  1592.    menu_ienable ( menu_addr, NEWYEAR, FALSE );
  1593.    menu_ienable ( menu_addr, NEWDATE, TRUE );
  1594. }
  1595.  
  1596.  
  1597. set_canc_menu ()
  1598. {
  1599.    menu_ienable ( menu_addr, CLOSEMBR, TRUE );
  1600.    menu_ienable ( menu_addr, OPENMBR, FALSE );
  1601.    menu_ienable ( menu_addr, QUIT, TRUE );
  1602.    menu_ienable ( menu_addr, NEWACCNT, FALSE );
  1603.    menu_ienable ( menu_addr, ENTER, FALSE );
  1604.    menu_ienable ( menu_addr, SEARCH, FALSE );
  1605.    menu_ienable ( menu_addr, CHKCAN, FALSE );
  1606.    menu_ienable ( menu_addr, CHKAUTO, FALSE );
  1607.    menu_ienable ( menu_addr, NEWMNTH, FALSE );
  1608.    menu_ienable ( menu_addr, RECONCIL, FALSE );
  1609.    menu_ienable ( menu_addr, PRNTWIND, TRUE );
  1610.    menu_ienable ( menu_addr, PRNTREG, TRUE );
  1611.    menu_ienable ( menu_addr, NEWYEAR, FALSE );
  1612.    menu_ienable ( menu_addr, NEWDATE, TRUE );
  1613. }
  1614.  
  1615.  
  1616. draw_interior ( clip )
  1617. GRECT clip;
  1618. {
  1619.    GRECT r;
  1620.    int lines_avail, lines_shown;
  1621.  
  1622.    graf_mouse ( M_OFF, 0L );
  1623.    vswr_mode ( handle, MD_REPLACE );
  1624.    if ( msg_buf[3] == w_h1 ) {
  1625.       if ( res == HIGH ) {
  1626.          r.g_x = 1;
  1627.          r.g_y = 337;
  1628.          r.g_w = 638;
  1629.          r.g_h = 63;
  1630.       }
  1631.       else {
  1632.          r.g_x = 1;
  1633.          r.g_y = 167;
  1634.          r.g_w = 638;
  1635.          r.g_h = 32;
  1636.       }
  1637.       draw_rec ( r, 2, 4, GREEN );
  1638.       draw_buttons ();
  1639.    }
  1640.    else {
  1641.       if ( !full_draw )
  1642.          set_clip ( TRUE, clip );
  1643.       wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  1644.       draw_rec ( r, 2, 8, WHITE );
  1645.       if ( full )
  1646.          lines_avail = 20;
  1647.       else
  1648.          lines_avail = 15;
  1649.       lines_shown = cur_count - cur_top;
  1650.       if ( lines_avail > lines_shown ) {
  1651.          cur_top = cur_count - lines_avail;
  1652.          if ( cur_top < 0 )
  1653.             cur_top = 0;
  1654.       }
  1655.       if ( cur_count == 0 )
  1656.          calc_vslid ( 1 );
  1657.       else
  1658.          calc_vslid ( cur_count );
  1659.       calc_hslid ( NUM_COLUMNS );
  1660.       updte_chk_wind ();
  1661.       full_draw = FALSE;
  1662.       set_clip ( FALSE, clip );
  1663.    }
  1664.    graf_mouse ( M_ON, 0L );
  1665. }
  1666.  
  1667.  
  1668. updte_chk_wind ()
  1669. {
  1670.    int i, y;
  1671.  
  1672.    wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh );
  1673.    i = cur_top;
  1674.    y = 0;
  1675.    while ( (i < cur_count) && (i < cur_top + wrkh / charh) ) {
  1676.       prnt_chk_wnd ( i, wrky + charh + y * charh );
  1677.       ++i;
  1678.       ++y;
  1679.    }
  1680. }
  1681.  
  1682.  
  1683. prnt_chk_wnd ( index, row )
  1684. int index, row;
  1685. {
  1686.    char a[40], s[10];
  1687.  
  1688.    if ( left ) {
  1689.       v_gtext ( handle, 6, row, cur_chk_strc[index].cancel );
  1690.       v_gtext ( handle, 25, row, cur_chk_strc[index].number );
  1691.       sprintf ( a, "$%5ld.%02ld",
  1692.          cur_chk_strc[index].amount/100, cur_chk_strc[index].amount%100 );
  1693.       v_gtext ( handle, 77, row, a );
  1694.       v_gtext ( handle, 169, row, cur_chk_strc[index].payee );
  1695.       strcpy ( a, cur_chk_strc[index].memo );
  1696.       a[24] = 0;
  1697.       v_gtext ( handle, 424, row, a );
  1698.    }
  1699.    else {
  1700.       v_gtext ( handle, 9, row, cur_chk_strc[index].payee );
  1701.       v_gtext ( handle, 264, row, cur_chk_strc[index].memo );
  1702.       strcpy ( s, cur_chk_strc[index].date );
  1703.       format_date ( a, s );
  1704.       v_gtext ( handle, 520, row, a );
  1705.    }
  1706. }
  1707.  
  1708.  
  1709. restore_amounts ( num )
  1710. int num;
  1711. {
  1712.    num_trans += 1;
  1713.    if ( strcmp ( checks[num].number, "9999" ) == MATCH ) {
  1714.       num_deps += 1;
  1715.       balance += checks[num].amount;
  1716.    }
  1717.    else {
  1718.       num_chks += 1;
  1719.       balance -= checks[num].amount;
  1720.    }
  1721. }
  1722.  
  1723.  
  1724. calc_vslid ( line_cnt )
  1725. int line_cnt;
  1726. {
  1727.    int lines_avail, vslid_siz, pos;
  1728.  
  1729.    if ( line_cnt == 0 )
  1730.       line_cnt = 1;
  1731.    wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh );
  1732.    lines_avail = wrkh / charh;
  1733.    vslid_siz = 1000 * lines_avail / line_cnt;
  1734.    wind_set ( w_h2, WF_VSLSIZE, vslid_siz, 0, 0, 0 );
  1735.    pos = (int) ( (float)(cur_top) ) / 
  1736.          ( (float)(line_cnt - lines_avail) ) * 1000;
  1737.    wind_set ( w_h2, WF_VSLIDE, pos, 0, 0, 0 );
  1738. }
  1739.  
  1740.  
  1741. calc_hslid ( col_cnt )
  1742. int col_cnt;
  1743. {
  1744.    int cols_avail, hslid_siz, pos, lft;
  1745.  
  1746.    if ( left )
  1747.       lft = 0;
  1748.    else
  1749.       lft = 16;
  1750.    wind_get ( w_h2, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh );
  1751.    cols_avail = wrkw / charw;
  1752.    hslid_siz = (int) ((1000L * (long) cols_avail) / (long) col_cnt);
  1753.    wind_set ( w_h2, WF_HSLSIZE, hslid_siz, 0, 0, 0 );
  1754.    pos = (int) ( (float)(lft) ) / ( (float)(col_cnt - cols_avail) ) * 1000;
  1755.    wind_set ( w_h2, WF_HSLIDE, pos, 0, 0, 0 );
  1756. }
  1757.  
  1758.  
  1759. do_enter ()
  1760. {
  1761.    int choice, okay;
  1762.    int dial_x, dial_y, dial_w, dial_h;
  1763.  
  1764.    set_chk_strings ();
  1765.    check_addr[CHKNEXT].ob_state = SHADOWED;
  1766.    check_addr[CHKNEXT].ob_flags = SELECTABLE | DEFAULT | TOUCHEXIT;
  1767.    check_addr[CHKDONE].ob_flags = SELECTABLE | TOUCHEXIT;
  1768.    form_center ( check_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1769.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1770.    objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1771.  
  1772.    okay = FALSE;
  1773.  
  1774.    do {
  1775.       choice = form_do ( check_addr, NUMBER );
  1776.       check_addr[choice].ob_state = SHADOWED;
  1777.  
  1778.       switch ( choice ) {
  1779.  
  1780.          case CHKDONE:
  1781.          case CHKNEXT:
  1782.             okay = validate_check ();
  1783.             if ( okay ) {
  1784.                saved = FALSE;
  1785.                move_check_data ( num_trans );
  1786.                strcpy ( checks[num_trans].cancel, " " );
  1787.                updte_amounts ( num_trans );
  1788.                updte_buttons ();
  1789.             }
  1790.             if ( choice != CHKDONE | !okay ) {
  1791.                if ( choice == CHKNEXT )
  1792.                   set_chk_strings ();
  1793.                objc_draw ( check_addr, 0, 8,
  1794.                            dial_x, dial_y, dial_w, dial_h );
  1795.             }
  1796.             break;
  1797.  
  1798.          case CHKCANCL:
  1799.             clear_check ();
  1800.             break;
  1801.       }
  1802.    }
  1803.    while ( (choice != CHKDONE | okay == FALSE) && choice != CHKCANCL );
  1804.  
  1805.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1806.    cur_count = num_trans;
  1807.    full_draw = TRUE;
  1808. }
  1809.  
  1810.  
  1811. open_acct ( file )
  1812. char *file;
  1813. {
  1814.    int x, len;
  1815.    char zip[10], buf[25];
  1816.  
  1817.    if ( ( acctfile = fopen ( file, "br" )) == 0 )
  1818.       form_alert ( 1, "[1][Can't open the file][CONTINUE]" );
  1819.    else {
  1820.       fread ( chkname, 1, 26, acctfile );
  1821.       fread ( chkstreet, 1, 26, acctfile );
  1822.       fread ( chkcity, 1, 16, acctfile );
  1823.       fread ( buf, 1, 10, acctfile );
  1824.       strcpy ( &chkcity[strlen(chkcity)], ", " );
  1825.       fread ( &chkcity[strlen(chkcity)], 1, 3, acctfile );
  1826.       strcpy ( &chkcity[strlen(chkcity)], "  " );
  1827.       fread ( zip, 1, 10, acctfile );
  1828.       len = strlen ( chkcity );
  1829.       if ( strlen ( zip ) > 5 ) {
  1830.          strncpy ( &chkcity[len], zip, 5 );
  1831.          chkcity[len+5] = 0;
  1832.          strcpy ( &chkcity[strlen(chkcity)], "-" );
  1833.          strcpy ( &chkcity[strlen(chkcity)], &zip[5] );
  1834.       }
  1835.       else
  1836.          strcpy ( &chkcity[strlen(chkcity)], zip );
  1837.       fread ( &balance, 4, 1, acctfile );
  1838.       if ( fclose ( acctfile ) != 0 )
  1839.             form_alert ( 1, "[1][File close error!][OKAY]");
  1840.       check_addr[CHKNAME].ob_spec = chkname;
  1841.       check_addr[CHKSTREE].ob_spec = chkstreet;
  1842.       check_addr[CHKCITY].ob_spec = chkcity;
  1843.       do_new_mnth ();
  1844.       if ( loaded )
  1845.          set_menu_entries ();
  1846.       else
  1847.          balance = 0;
  1848.    }
  1849. }
  1850.  
  1851.  
  1852. edit ()
  1853. {
  1854.    int line, index, x;
  1855.    char s[10], t[10];
  1856.  
  1857.    line = ( mouse_y - wrky - 4 ) / charh;
  1858.    index = line + cur_top;
  1859.    num_trans -= 1;
  1860.    string = get_tedinfo_str ( check_addr, PAYEE );
  1861.    strcpy ( string, checks[index].payee );
  1862.    x = strlen ( string ) - 1;
  1863.    while ( string[x--] == ' ' );
  1864.    string[x+2] = 0;
  1865.    string = get_tedinfo_str ( check_addr, MEMO );
  1866.    strcpy ( string, checks[index].memo );
  1867.    x = strlen ( string ) - 1;
  1868.    while ( string[x--] == ' ' );
  1869.    string[x+2] = 0;
  1870.    string = get_tedinfo_str ( check_addr, NUMBER );
  1871.    strcpy ( string, checks[index].number );
  1872.    if ( strcmp ( string, "9999" ) != MATCH ) {
  1873.       balance += checks[index].amount;
  1874.       num_chks -= 1;
  1875.    }
  1876.    else {
  1877.       balance -= checks[index].amount;
  1878.       num_deps -= 1;
  1879.    }
  1880.    string = get_tedinfo_str ( check_addr, DATE );
  1881.    strcpy ( string, checks[index].date );
  1882.    string = get_tedinfo_str ( check_addr, PAID );
  1883.    strcpy ( string, checks[index].cancel );
  1884.    sprintf ( s, "%ld.%02ld", checks[index].amount/100, checks[index].amount%100 );
  1885.    x = 0;
  1886.    while ( s[x] != '.' && x<strlen(s) )
  1887.       ++x;
  1888.    strcpy ( t, "       " );
  1889.    strncpy ( t, s, x );
  1890.    t[x] = ' ';
  1891.    strcpy ( &t[5], &s[x+1] );
  1892.    string = get_tedinfo_str ( check_addr, AMOUNT );
  1893.    strcpy ( string, t );
  1894.    edit_check ( index );
  1895. }
  1896.  
  1897.  
  1898. edit_check ( num )
  1899. int num;
  1900. {
  1901.    int okay, choice;
  1902.    int dial_x, dial_y, dial_w, dial_h;
  1903.  
  1904.    check_addr[CHKNEXT].ob_state = DISABLED;
  1905.    check_addr[CHKNEXT].ob_flags = NONE;
  1906.    check_addr[CHKDONE].ob_flags = SELECTABLE | DEFAULT | TOUCHEXIT;
  1907.    form_center ( check_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  1908.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1909.    objc_draw ( check_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  1910.  
  1911.    okay = FALSE;
  1912.  
  1913.    do {
  1914.       choice = form_do ( check_addr, NUMBER );
  1915.       check_addr[choice].ob_state = SHADOWED;
  1916.  
  1917.       switch ( choice ) {
  1918.  
  1919.          case CHKDONE:
  1920.             okay = validate_check ();
  1921.             if ( okay ) {
  1922.                saved = FALSE;
  1923.                move_check_data ( num );
  1924.                updte_amounts ( num );
  1925.                graf_mouse ( M_OFF, 0L );
  1926.                prnt_chk_wnd ( num, wrky + charh + (num-cur_top) * charh );
  1927.                updte_buttons ();
  1928.                graf_mouse ( M_ON, 0L );
  1929.             }
  1930.             else 
  1931.                objc_draw ( check_addr, 0, 8,
  1932.                            dial_x, dial_y, dial_w, dial_h );
  1933.             break;
  1934.  
  1935.          case CHKCANCL:
  1936.             restore_amounts ( num );
  1937.             clear_check ();
  1938.             break;
  1939.       }
  1940.    }
  1941.    while ( (choice != CHKDONE | !okay ) && choice != CHKCANCL );
  1942.  
  1943.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  1944. }
  1945.  
  1946.  
  1947. draw_rec ( rec, inter, fill, color )
  1948. GRECT rec;
  1949. int inter, fill, color;
  1950. {
  1951.    int pxy[4];
  1952.  
  1953.    graf_mouse ( M_OFF, 0L );
  1954.    vsf_interior ( handle, inter );
  1955.    vsf_style ( handle, fill );
  1956.    vsf_color ( handle, color );
  1957.    pxy[0] = rec.g_x;
  1958.    pxy[1] = rec.g_y;
  1959.    pxy[2] = rec.g_x + rec.g_w - 1;
  1960.    pxy[3] = rec.g_y + rec.g_h - 1;
  1961.    vr_recfl ( handle, pxy );
  1962.    graf_mouse ( M_ON, 0L );
  1963. }
  1964.  
  1965.  
  1966. set_buttons ()
  1967. {
  1968.    if ( balance < 0 && balance > (-100) )
  1969.       sprintf ( bal_but, "$-%ld.%02ld", balance/100, labs(balance%100) );
  1970.    else
  1971.       sprintf ( bal_but, "$%ld.%02ld", balance/100, labs(balance%100) );
  1972.    sprintf ( trans_but, "%d", num_trans );
  1973.    sprintf ( check_but, "%d", num_chks );
  1974.    sprintf ( dep_but, "%d", num_deps );
  1975.    if ( month == -1 )
  1976.       strcpy ( mnth_but, "NONE" );
  1977.    else
  1978.       strcpy ( mnth_but, months[month] );
  1979. }
  1980.  
  1981.  
  1982. set_chk_strings ()
  1983. {
  1984.    string = get_tedinfo_str ( check_addr, NUMBER );
  1985.    strcpy ( string, cur_chk_num );
  1986.    string = get_tedinfo_str ( check_addr, DATE );
  1987.    strcpy ( string, cur_date );
  1988.    string = get_tedinfo_str ( check_addr, PAYEE );
  1989.    string[0] = '@';
  1990.    string = get_tedinfo_str ( check_addr, AMOUNT );
  1991.    string[0] = '@';
  1992.    string = get_tedinfo_str ( check_addr, MEMO );
  1993.    string[0] = '@';
  1994.    string = get_tedinfo_str ( check_addr, PAID );
  1995.    string[0] = 0;
  1996. }
  1997.  
  1998.  
  1999. clear_newacct ()
  2000. {
  2001.    int x;
  2002.  
  2003.    for ( x=NEWNAME; x<=NEWBALNC; ++x ) {
  2004.       string = get_tedinfo_str ( newacct_addr, x );
  2005.       string[0] = '@';
  2006.    }
  2007.    newacct_addr[NEWCANCL].ob_state = SHADOWED;
  2008. }
  2009.  
  2010.  
  2011. clear_check ()
  2012. {
  2013.    string = get_tedinfo_str ( check_addr, PAYEE );
  2014.    string[0] = '@';
  2015.    string = get_tedinfo_str ( check_addr, AMOUNT );
  2016.    string[0] = '@';
  2017.    string = get_tedinfo_str ( check_addr, MEMO );
  2018.    string[0] = '@';
  2019. }
  2020.  
  2021.  
  2022. do_redraw ( rec1 )
  2023. GRECT *rec1;
  2024. {
  2025.    GRECT rec2;
  2026.  
  2027.    wind_update ( BEG_UPDATE );
  2028.    wind_get ( msg_buf[3], WF_FIRSTXYWH,
  2029.               &rec2.g_x, &rec2.g_y, &rec2.g_w, &rec2.g_h );
  2030.  
  2031.    while ( rec2.g_w && rec2.g_h ) {
  2032.       if ( rc_intersect ( rec1, &rec2 ) )
  2033.          draw_interior ( rec2 );
  2034.       wind_get ( msg_buf[3], WF_NEXTXYWH,
  2035.                 &rec2.g_x, &rec2.g_y, &rec2.g_w, &rec2.g_h );
  2036.    }
  2037.    wind_update ( END_UPDATE );
  2038. }
  2039.  
  2040.  
  2041. set_clip ( flag, rec )
  2042. int flag;
  2043. GRECT rec;
  2044. {
  2045.    int pxy[4];
  2046.  
  2047.    pxy[0] = rec.g_x;
  2048.    pxy[1] = rec.g_y;
  2049.    pxy[2] = rec.g_x + rec.g_w - 1;
  2050.    pxy[3] = rec.g_y + rec.g_h - 1;
  2051.    vs_clip ( handle, flag, pxy );
  2052. }
  2053.  
  2054.  
  2055. open_vwork ()
  2056. {
  2057.    int i;
  2058.  
  2059.    handle = graf_handle ( &charw, &charh, &dum, &dum);
  2060.    for ( i=0; i<10; work_in[i++] = 1 );
  2061.    work_in[10] = 2;
  2062.    v_opnvwk ( work_in, &handle, work_out );
  2063. }
  2064.  
  2065.  
  2066. draw_buttons()
  2067. {
  2068.    set_buttons ();
  2069.    button ( "BALANCE", bal_but, 35 );
  2070.    button ( "# TRANS", trans_but, 131 );
  2071.    button ( "# CHECKS", check_but, 227 );
  2072.    button ( "# DEP", dep_but, 323 );
  2073.    button ( "MONTH", mnth_but, 419 );
  2074.    button ( "DATE", date_but, 515 );
  2075. }
  2076.  
  2077.  
  2078. button ( str1, str2, x1 )
  2079. char *str1, *str2;
  2080. int x1;
  2081. {
  2082.       int x2, y1, y2;
  2083.       int pxy[10];
  2084.  
  2085.       x2 = x1 + 88;
  2086.       y1 = 174 * res;
  2087.       y2 = 198 * res;
  2088.       vswr_mode ( handle, MD_REPLACE );
  2089.       vsf_color ( handle, WHITE );
  2090.       pxy[0] = x1;
  2091.       pxy[1] = y1;
  2092.       pxy[2] = x2;
  2093.       pxy[3] = y2;
  2094.       v_bar ( handle, pxy );
  2095.       pxy[3] = y1;
  2096.       pxy[4] = x2;
  2097.       pxy[5] = y2;
  2098.       pxy[6] = x1;
  2099.       pxy[7] = y2;
  2100.       pxy[8] = x1;
  2101.       pxy[9] = y1;
  2102.       vsl_width ( handle, 3 );
  2103.       vsl_color ( handle, BLACK );
  2104.       v_pline ( handle, 5, pxy );
  2105.       center_butstring ( str1, x1, 184);
  2106.       center_butstring ( str2, x1, 194);
  2107. }
  2108.  
  2109.  
  2110. center_butstring ( str, x1, y )
  2111. char *str;
  2112. int x1, y;
  2113. {
  2114.    int x, x2;
  2115.  
  2116.    x2 = x1 + 88;
  2117.    x = ((x2-x1)-(strlen(str)*8))/2+x1;
  2118.    v_gtext ( handle, x1+5, y * res, "          " );
  2119.    v_gtext ( handle, x, y * res, str ); 
  2120. }
  2121.  
  2122.  
  2123. get_date ()
  2124. {
  2125.    int date, day, mnth, year;
  2126.    char d[3], m[3], y[4];
  2127.  
  2128.    date = Tgetdate ();
  2129.    day = date & 0x001f;
  2130.    mnth = (date >> 5) & 0x000f;
  2131.    year = ((date >> 9) & 0x007f) + 80;
  2132.    year = year % 100;
  2133.    sprintf ( d, "%d", day );
  2134.    sprintf ( m, "%d", mnth );
  2135.    sprintf ( y, "%d", year );
  2136.    if ( mnth < 10 ) {
  2137.       date_but[0] = '0';
  2138.       cur_date[0] = '0';
  2139.       strcpy ( &date_but[1], m );
  2140.       strcpy ( &cur_date[1], m );
  2141.    }
  2142.    else {
  2143.       strcpy ( date_but, m );
  2144.       strcpy ( cur_date, m );
  2145.    }
  2146.    date_but[2] = '/';
  2147.    if ( day < 10 ) {
  2148.       date_but[3] = '0';
  2149.       cur_date[2] = '0';
  2150.       strcpy ( &date_but[4], d );
  2151.       strcpy ( &cur_date[3], d );
  2152.    }
  2153.    else {
  2154.       strcpy ( &date_but[3], d );
  2155.       strcpy ( &cur_date[2], d );
  2156.    }
  2157.    date_but[5] = '/';
  2158.    if ( year < 10 ) {
  2159.       date_but[6] = '0';
  2160.       cur_date[4] = '0';
  2161.       strcpy ( &date_but[7], y );
  2162.       strcpy ( &cur_date[5], y );
  2163.    }
  2164.    else {
  2165.       strcpy ( &date_but[6], y );
  2166.       strcpy ( &cur_date[4], y );
  2167.    }
  2168. }
  2169.  
  2170.  
  2171. char *get_tedinfo_str ( tree, object )
  2172. OBJECT *tree;
  2173. int object;
  2174. {
  2175.    TEDINFO *ob_tedinfo;
  2176.  
  2177.    ob_tedinfo = (TEDINFO *) tree[object].ob_spec;
  2178.    return ( ob_tedinfo->te_ptext );
  2179. }
  2180.  
  2181.  
  2182. select_file ( path, fnme, deflt, display)
  2183. char *path, *fnme, *deflt;
  2184. int display;
  2185. {
  2186.    int x, choice;
  2187.    char ch;
  2188.  
  2189.    if ( display == FALSE )
  2190.       for ( x=0; x<20; fnme[x++] = '\0' );
  2191.  
  2192.    Dgetpath ( path, 0 );
  2193.    strcpy ( &path[strlen(path)], "\\" );
  2194.    strcpy ( &path[strlen(path)], deflt );
  2195.  
  2196.    fsel_input ( path, fnme, &choice );
  2197.  
  2198.    x = strlen ( path );
  2199.    while ( ( ch = path[--x] ) != '\\' && x > 0 );
  2200.    path[x+1] = '\0';
  2201.  
  2202.    return ( choice );
  2203. }
  2204.  
  2205.  
  2206. write_new_info ()
  2207. {
  2208.    int len, x;
  2209.    char s[10], tmpfile[64];
  2210.    FILE *f;
  2211.  
  2212.    string = get_tedinfo_str ( newacct_addr, NEWNAME );
  2213.    fwrite ( string, 1, 26, acctfile );
  2214.    string = get_tedinfo_str ( newacct_addr, NEWADDR );
  2215.    fwrite ( string, 1, 26, acctfile );
  2216.    string = get_tedinfo_str ( newacct_addr, NEWCITY );
  2217.    fwrite ( string, 1, 26, acctfile );
  2218.    string = get_tedinfo_str ( newacct_addr, NEWSTATE );
  2219.    fwrite ( string, 1, 3, acctfile );
  2220.    string = get_tedinfo_str ( newacct_addr, NEWZIP );
  2221.    fwrite ( string, 1, 10, acctfile );
  2222.    string = get_tedinfo_str ( newacct_addr, NEWBALNC );
  2223.    no_decimal ( string );
  2224.    balance = str_to_long ( string );
  2225.    fwrite ( &balance, 1, 4, acctfile );
  2226.    if ( fclose ( acctfile ) != 0 )
  2227.       form_alert ( 1, "[1][File close error!][OKAY]");
  2228.    for ( x=0; x<13; ++x ) {
  2229.       sprintf ( s, "%d", x );
  2230.       strcpy ( &s[strlen(s)], ".dat" );
  2231.       ob_tedinfo = (TEDINFO *) newfile_addr[FILENAME].ob_spec;
  2232.       tmpfile[0] = Dgetdrv () + 'a';
  2233.       strcpy ( &tmpfile[1], ":" );
  2234.       Dgetpath ( &tmpfile[strlen(tmpfile)], DFLT_DRV );
  2235.       strcpy ( &tmpfile[strlen(tmpfile)], "\\" );
  2236.       strcpy ( &tmpfile[strlen(tmpfile)], ob_tedinfo->te_ptext );
  2237.       strcpy ( &tmpfile[strlen(tmpfile)], s );
  2238.       if ( ( f = fopen ( tmpfile, "bw" ) ) == NULL )
  2239.          form_alert ( 1, "[1][Error creating file!][OK]" );
  2240.       else
  2241.          fwrite ( &zero, 2, 1, f );
  2242.       if ( fclose ( f ) != 0 )
  2243.             form_alert ( 1, "[1][File close error!][OK]");
  2244.    }
  2245. }
  2246.  
  2247.  
  2248. validate_check ()
  2249. {
  2250.    int okay, len;
  2251.    char a, d;
  2252.  
  2253.    okay = FALSE;
  2254.    if ( num_trans == 500 )
  2255.       form_alert(1,"[1][This month cannot hold  |any more transactions.  | |The maximum number of   |transactions is 500.][OK]");
  2256.    else {
  2257.       string = get_tedinfo_str ( check_addr, AMOUNT );
  2258.       a = string[0];
  2259.       string = get_tedinfo_str ( check_addr, DATE );
  2260.       len = strlen ( string );
  2261.       d = string[0];
  2262.       if ( a == '@' )
  2263.          form_alert ( 1, "[1][You must fill in|an amount!][Okay]" );
  2264.       else if ( len < 6 | d == '@' )
  2265.          form_alert ( 1, "[1][You must complete|the date field!][OKAY]" );
  2266.       else
  2267.          okay = TRUE;
  2268.    }
  2269.    return ( okay );
  2270. }
  2271.  
  2272.  
  2273. move_check_data ( number )
  2274. int number;
  2275. {
  2276.    int len;
  2277.    long amount;
  2278.    char t[10], a, d;
  2279.  
  2280.    string = get_tedinfo_str ( check_addr, AMOUNT );
  2281.    no_decimal ( string );
  2282.    amount = str_to_long ( string );
  2283.    checks[number].amount = amount;
  2284.    string[0] = '@';
  2285.    string = get_tedinfo_str ( check_addr, PAYEE );
  2286.    strcpy ( checks[number].payee, string );
  2287.    if ( checks[number].payee[0] == '@' )
  2288.       strcpy ( checks[number].payee, spaces );
  2289.    else {
  2290.       len = strlen ( checks[number].payee );
  2291.       strcpy ( &checks[number].payee[len], &spaces[len] );
  2292.    }
  2293.    string[0] = '@';
  2294.    string = get_tedinfo_str ( check_addr, MEMO );
  2295.    strcpy ( checks[number].memo, string );
  2296.    if ( checks[number].memo[0] == '@' )
  2297.       strcpy ( checks[number].memo, spaces );
  2298.    else {
  2299.       len = strlen ( checks[number].memo );
  2300.       strcpy ( &checks[number].memo[len], &spaces[len] );
  2301.    }
  2302.    string[0] = '@';
  2303.    string = get_tedinfo_str ( check_addr, DATE );
  2304.    strcpy ( checks[number].date, string );
  2305.    strcpy ( cur_date, string );
  2306.    string = get_tedinfo_str ( check_addr, NUMBER );
  2307.    len = strlen ( string );
  2308.    if ( len == 4 )
  2309.      strcpy ( cur_chk_num, string );
  2310.    else {
  2311.       strcpy ( cur_chk_num, "0000" );
  2312.       strcpy ( &cur_chk_num[4-len], string );
  2313.    }
  2314.    strcpy ( checks[number].number, cur_chk_num );
  2315.    curchknum = atoi ( cur_chk_num );
  2316. }
  2317.  
  2318.  
  2319. updte_amounts ( num )
  2320. int num;
  2321. {
  2322.    char t[20];
  2323.    int len;
  2324.  
  2325.    if ( strcmp ( checks[num].number, "9999" ) == MATCH ) {
  2326.       strcpy ( checks[num].payee, "DEPOSIT                       " );
  2327.       balance += checks[num].amount;
  2328.       num_deps += 1;
  2329.    }
  2330.    else {
  2331.       num_chks += 1;
  2332.       curchknum += 1;
  2333.       sprintf ( t, "%d", curchknum );
  2334.       len = strlen ( t );
  2335.       strcpy ( &cur_chk_num[4-len], t );
  2336.       balance -= checks[num].amount;
  2337.    }
  2338.    num_trans += 1;
  2339.    cur_count = num_trans;
  2340. }
  2341.  
  2342.  
  2343. updte_buttons ()
  2344. {
  2345.    if ( !full ) {
  2346.       set_buttons ();
  2347.       center_butstring ( bal_but, 35, 194 );
  2348.       center_butstring ( trans_but, 131, 194 );
  2349.       center_butstring ( check_but, 227, 194 );
  2350.       center_butstring ( dep_but, 323, 194 );
  2351.       center_butstring ( mnth_but, 419, 194 );
  2352.       center_butstring ( date_but, 515, 194 );
  2353.    }
  2354. }
  2355.  
  2356.  
  2357. do_newacct ()
  2358. {
  2359.    int choice, okay;
  2360.    int dial_x, dial_y, dial_w, dial_h;
  2361.  
  2362.    clear_newacct ();
  2363.    form_center ( newacct_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  2364.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  2365.    objc_draw ( newacct_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  2366.  
  2367.    do {
  2368.       choice = form_do ( newacct_addr, NEWNAME );
  2369.       newacct_addr[choice].ob_state = SHADOWED;
  2370.  
  2371.       switch ( choice ) {
  2372.  
  2373.          case NEWOK:
  2374.             okay = check_newacct ();
  2375.             if ( !okay )
  2376.                objc_draw ( newacct_addr, 0, 8, 
  2377.                            dial_x, dial_y, dial_w, dial_h );
  2378.             else
  2379.                newacct_file ();
  2380.             break;
  2381.             
  2382.          case NEWCANCL:
  2383.             clear_newacct ();
  2384.       }
  2385.    }
  2386.    while ( okay == FALSE && choice != NEWCANCL );
  2387.  
  2388.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  2389. }
  2390.  
  2391.  
  2392. check_newacct ()
  2393. {
  2394.    int x, okay;
  2395.  
  2396.    okay = TRUE;
  2397.    for ( x=NEWNAME; x<=NEWBALNC; ++x ) {
  2398.       string = get_tedinfo_str ( newacct_addr, x );
  2399.       if ( string[0] == '@' )
  2400.          okay = FALSE;
  2401.    }
  2402.    if ( !okay )
  2403.       form_alert(1,"[1][You must complete|the form to start|a new account!][OK]");
  2404.    return ( okay );
  2405. }
  2406.    
  2407.       
  2408. newacct_file ()
  2409. {
  2410.    int choice, okay, x;
  2411.    int dial_x, dial_y, dial_w, dial_h;
  2412.  
  2413.    string = get_tedinfo_str ( newfile_addr, FILENAME );
  2414.    string[0] = 0;
  2415.    for ( x=0; x<64; filename[x++]=0 );
  2416.    newfile_addr[NEWOK].ob_state = SHADOWED;
  2417.    form_center ( newfile_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  2418.    form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  2419.    objc_draw ( newfile_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  2420.  
  2421.    do {
  2422.       choice = form_do ( newfile_addr, FILENAME );
  2423.       newfile_addr[choice].ob_state = SHADOWED;
  2424.  
  2425.       switch ( choice ) {
  2426.  
  2427.          case FILEOK:
  2428.             okay = check_file ();
  2429.             if ( !okay )
  2430.                objc_draw ( newfile_addr, 0, 8, 
  2431.                            dial_x, dial_y, dial_w, dial_h );
  2432.             else {
  2433.                string = get_tedinfo_str ( newfile_addr, FILENAME );
  2434.                strcpy ( acct_name, string );
  2435.                filename[0] = Dgetdrv () + 'a';
  2436.                filename[1] = ':';
  2437.                Dgetpath ( &filename[2], DFLT_DRV );
  2438.                filename[strlen(filename)] = '\\';
  2439.                strcpy ( &filename[strlen(filename)], string );
  2440.                strcpy ( &filename[strlen(filename)], ".MCK" );
  2441.                acctfile = fopen ( filename, "bw" );
  2442.                if ( acctfile != 0 ) {
  2443.                   write_new_info ();
  2444.                   open_acct ( filename );
  2445.                }
  2446.             }
  2447.             break;
  2448.  
  2449.          case FILECANC:
  2450.             string = get_tedinfo_str ( newfile_addr, FILENAME );
  2451.             string[0] = 0;
  2452.       }
  2453.    }
  2454.    while ( !okay && choice != FILECANC );
  2455.  
  2456.    form_dial ( FMD_FINISH, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  2457. }
  2458.  
  2459.  
  2460. check_file ()
  2461. {
  2462.    int okay;
  2463.  
  2464.    okay = TRUE;
  2465.    string = get_tedinfo_str ( newfile_addr, FILENAME );
  2466.    if ( strlen ( string ) == 0 ) {
  2467.       form_alert(1,"[1][Invalid filename!][OK]");
  2468.       okay = FALSE;
  2469.    }
  2470.    return ( okay );
  2471. }
  2472.  
  2473.  
  2474. do_quit ()
  2475. {
  2476.    int button;
  2477.  
  2478.    button = form_alert(1,"[2][Are you sure you|want to quit?][YES|NO]");
  2479.    if ( button == YES ) {
  2480.       search = FALSE;
  2481.       all_done = TRUE;
  2482.       if ( !saved )
  2483.          do_save ();
  2484.    }
  2485. }
  2486.  
  2487.  
  2488. get_acct ()
  2489. {
  2490.    char path[64];
  2491.    int button;
  2492.  
  2493.    button = select_file ( path, acct_name, "*.MCK", FALSE );
  2494.    if ( strlen (acct_name) == 0 )
  2495.       button = 0;
  2496.    if ( button ) {
  2497.       strcpy ( filename, path );
  2498.       strcpy ( &filename[strlen(filename)], acct_name );
  2499.       acct_name[ strlen(acct_name) - 4 ] = 0;
  2500.    }
  2501.    return ( button );
  2502. }
  2503.  
  2504.  
  2505. do_import ()
  2506. {
  2507.    int button, x, i, cnt, choice;
  2508.    char infile[64], outfile[64], s[10];
  2509.    char *string;
  2510.    FILE *file1, *file2;
  2511.  
  2512.    button = form_alert(1,"[2][The ported 8-bit MicroCheck|files must be in the same|directory from which you|loaded this program.|Are you ready?][YES|NO]");
  2513.    if ( button == YES ) {
  2514.       choice = get_acct ();
  2515.       if ( choice ) {
  2516.          for ( x=0; x<13; ++x ) {
  2517.             sprintf ( s, "%d", x );
  2518.             strcpy ( &s[strlen(s)], ".DAT" );
  2519.             strcpy ( infile, filename );
  2520.             strcpy ( outfile, infile );
  2521.             strcpy ( &infile[strlen(infile)-4], s );
  2522.             if ( x > 9 )
  2523.                sprintf ( s, "%d", x );
  2524.             else {
  2525.                s[0] = '0';
  2526.                sprintf ( &s[1], "%d", x );
  2527.             }
  2528.             strcpy ( &s[strlen(s)], ".dat" );
  2529.             for ( i=strlen(outfile)-1; i>0 && outfile[i] != '\\'; --i );
  2530.             strcpy ( &outfile[i+1], "MONTH" );
  2531.             strcpy ( &outfile[strlen(outfile)], s );
  2532.             if ( ( file1 = fopen ( infile, "bw" ) ) == NULL )
  2533.                form_alert ( 1, "[1][Error creating file!][OK]" );
  2534.             else if ( ( file2 = fopen ( outfile, "br" ) ) == NULL ) {
  2535.                fwrite ( &zero, 2, 1, file1 );
  2536.                if ( fclose ( file1 ) != 0 )
  2537.                   form_alert ( 1, "[1][File close error!][OK]");
  2538.             }
  2539.             else {
  2540.                cnt = read_old_checks ( file2 );
  2541.                fwrite ( &cnt, 2, 1, file1 );
  2542.                for ( i=0; i<cnt; ++i )
  2543.                   save_check ( i, file1 );
  2544.                fclose ( file1 );
  2545.             }
  2546.          }
  2547.       }
  2548.    }
  2549. }
  2550.  
  2551.  
  2552. read_old_checks ( f )
  2553. FILE *f;
  2554. {
  2555.    int cnt, i;
  2556.    char test[4], s[10], s2[30];
  2557.  
  2558.    cnt = 0;
  2559.    fread ( test, 1, 3, f );
  2560.    test[3] = 0;
  2561.    while ( strcmp ( test, "END" ) != MATCH ) {
  2562.       checks[cnt].cancel[0] = test[0];
  2563.       checks[cnt].cancel[1] = 0;
  2564.       strcpy ( checks[cnt].number, &test[1] );
  2565.       fread ( &checks[cnt].number[2], 1, 2, f );
  2566.       checks[cnt].number[4] = 0;
  2567.       if ( strcmp ( checks[cnt].number, "DEP " ) == MATCH )
  2568.          strcpy ( checks[cnt].number, "9999" );
  2569.       else if ( strcmp ( checks[cnt].number, "AUTO" ) == MATCH ) {
  2570.          strcpy ( checks[cnt].number, "0000" );
  2571.          strcpy ( checks[cnt].memo, "AUTO                          " );
  2572.       }
  2573.       fread ( s, 1, 8, f );
  2574.       strcpy ( checks[cnt].date, s );
  2575.       strcpy ( &checks[cnt].date[2], &s[3] );
  2576.       strcpy ( &checks[cnt].date[4], &s[6] );
  2577.       fread ( checks[cnt].payee, 1, 21, f );
  2578.       strcpy ( &checks[cnt].payee[21], "         " );
  2579.       checks[cnt].payee[30] = 0;
  2580.       fread ( s, 1, 7, f );
  2581.       s[7] = 0;
  2582.       for ( i=0; i<7 && s[i] != '.'; ++i );
  2583.       strcpy ( s2, s );
  2584.       strcpy ( &s2[i], "     " );
  2585.       strcpy ( &s2[5], &s[i+1] );
  2586.       no_decimal ( s2 );
  2587.       checks[cnt].amount = str_to_long ( s2 );
  2588.       fread ( s2, 1, 22, f );
  2589.       if ( strcmp ( checks[cnt].memo, "AUTO                          " ) != MATCH ) {
  2590.          strcpy ( checks[cnt].memo, s2 );
  2591.          strcpy ( &checks[cnt].memo[22], "        " );
  2592.       }
  2593.       ++cnt;
  2594.       fread ( test, 1, 1, f );
  2595.       fread ( test, 1, 3, f );
  2596.    }
  2597.    return ( cnt );
  2598. }
  2599.  
  2600.  
  2601. save_check ( i, f )
  2602. int i;
  2603. FILE *f;
  2604. {
  2605.    fwrite ( checks[i].number, 1, 4, f );
  2606.    fwrite ( checks[i].payee, 1, 30, f );
  2607.    fwrite ( checks[i].memo, 1, 30, f );
  2608.    fwrite ( checks[i].date, 1, 8, f );
  2609.    fwrite ( &checks[i].amount, 4, 1, f );
  2610.    fwrite ( checks[i].cancel, 1, 1, f );
  2611.    fwrite ( "THIS SPACE FOR POSSIBLE FUTURE EXPANSION", 1, 40, f );
  2612. }
  2613.  
  2614.  
  2615. read_check ( i, f )
  2616. int i;
  2617. FILE f;
  2618. {
  2619.    fread ( checks[i].number, 1, 4, f );
  2620.    fread ( checks[i].payee, 1, 30, f );
  2621.    fread ( checks[i].memo, 1, 30, f );
  2622.    fread ( checks[i].date, 1, 8, f );
  2623.    fread ( &checks[i].amount, 4, 1, f );
  2624.    fread ( checks[i].cancel, 1, 1, f );
  2625.    fread ( future_use, 1, 40, f );
  2626. }
  2627.  
  2628.  
  2629. clear_window ()
  2630. {
  2631.    GRECT r;
  2632.  
  2633.    wind_get ( w_h2, WF_WORKXYWH, &r.g_x, &r.g_y, &r.g_w, &r.g_h );
  2634.    draw_rec ( r, 2, 8, WHITE );
  2635. }
  2636.  
  2637.  
  2638. print_wind ()
  2639. {
  2640.    int x, c, sp, lines, page, i, stop, key, key_stat, c_cnt, d_cnt;
  2641.    char s[10], amnt[10], date1[10], date2[10], acct[64];
  2642.    long c_tot, d_tot;
  2643.  
  2644.  
  2645.    stop = FALSE;
  2646.    c_cnt = d_cnt = 0;
  2647.    c_tot = d_tot = 0.00;
  2648.    if ( !Cprnos () )
  2649.       form_alert ( 1, "[1][Printer not ready!][OK]");
  2650.    else {
  2651.       page = 1;
  2652.       strcpy ( acct, filename );
  2653.       acct[strlen(acct)-4] = 0;
  2654.       lines = top_of_page ( page, acct, TRUE );
  2655.       Cprnout ( '\r' );
  2656.       Cprnout ( '\n' );
  2657.       lines += 1;
  2658.       x = 0;
  2659.       while ( x<cur_count && !stop ) {
  2660.          if ( strcmp ( cur_chk_strc[x].cancel, "*" ) == MATCH )
  2661.             Cprnout ( '*' );
  2662.          else
  2663.             Cprnout ( ' ' );
  2664.          Cprnout ( ' ' );
  2665.          for ( c=0; c<4; Cprnout ( cur_chk_strc[x].number[c++] ) );
  2666.          Cprnout ( ' ' );
  2667.          amnt[0]='$';
  2668.          sprintf ( s, "%ld.%02ld", cur_chk_strc[x].amount/100, 
  2669.                        cur_chk_strc[x].amount%100 );
  2670.          sp = 8 - strlen ( s );
  2671.          for ( c=0; c<sp; amnt[1+c++] = ' ' );
  2672.          strcpy ( &amnt[sp+1], s );
  2673.          for ( c=0; c<9; Cprnout ( amnt[c++] ) );
  2674.          Cprnout ( ' ' );
  2675.          for ( c=0; c<26; Cprnout ( cur_chk_strc[x].payee[c++] ) );
  2676.          Cprnout ( ' ' );
  2677.          for ( c=0; c<26; Cprnout ( cur_chk_strc[x].memo[c++] ) );
  2678.          Cprnout ( ' ' );
  2679.          strcpy ( date2, cur_chk_strc[x].date );
  2680.          format_date ( date1, date2 );
  2681.          for ( c=0; c<8; Cprnout ( date1[c++] ) );
  2682.          Cprnout ( '\r' );
  2683.          Cprnout ( '\n' );
  2684.          lines += 1;
  2685.          if ( lines > 61 ) {
  2686.             page += 1;
  2687.             lines = top_of_page ( page, acct, FALSE );
  2688.          }
  2689.          if ( strcmp ( cur_chk_strc[x].number, "9999" ) == MATCH ) {
  2690.             ++d_cnt;
  2691.             d_tot += cur_chk_strc[x].amount;
  2692.          }
  2693.          else {
  2694.             ++c_cnt;
  2695.             c_tot += cur_chk_strc[x].amount;
  2696.          }
  2697.          ++x;
  2698.          if ( ( key_stat = Bconstat ( CONSOLE ) ) == CHAR_AVAIL )
  2699.             if ( ( key = Bconin ( CONSOLE ) ) == ESCAPE )
  2700.                stop = TRUE;
  2701.       }
  2702.       if ( lines > 59 ) {
  2703.          page += 1;
  2704.          lines = top_of_page ( page, acct, FALSE );
  2705.       }
  2706.       print_totals ( c_cnt, d_cnt, c_tot, d_tot );
  2707.       Cprnout ( '\f' );
  2708.    }
  2709. }
  2710.  
  2711.  
  2712. print_reg ()
  2713. {
  2714.    char mfilename[64], check[85], amnt_str[10], acct[64], num[10];
  2715.    int len, m, numtrans, c, i, al, lines, page, stop, 
  2716.        key, key_stat, c_cnt, d_cnt;
  2717.    long amnt, c_tot, d_tot;
  2718.  
  2719.    if ( !saved )
  2720.       save_month ( monthfile );
  2721.    stop = FALSE;
  2722.    if ( !Cprnos () )
  2723.       form_alert ( 1, "[1][Printer not ready!][OK]");
  2724.    else {
  2725.       page = 1;
  2726.       c_cnt = d_cnt = 0;
  2727.       c_tot = d_tot = 0;
  2728.       for ( c=0; c<80; check[c++]=' ' );
  2729.       check[7] = '$';
  2730.       check[73] = '/';
  2731.       check[76] = '/';
  2732.       check[79] = 0;
  2733.       strcpy ( mfilename, filename );
  2734.       mfilename[strlen(mfilename)-4] = 0;
  2735.       strcpy ( acct, mfilename );
  2736.       len = strlen ( mfilename );
  2737.       lines = top_of_page ( page, acct, TRUE );
  2738.       m = 0;
  2739.       while ( m<13 && !stop ) {
  2740.          sprintf ( &mfilename[len], "%d", m );
  2741.          strcpy ( &mfilename[strlen(mfilename)], ".DAT" );
  2742.          if ( ( mfile = fopen ( mfilename, "br" )) == 0 )
  2743.             form_alert ( 1, "[1][Can't open the file][CONTINUE]" );
  2744.          else {
  2745.             fread ( &numtrans, 2, 1, mfile );
  2746.             if ( numtrans > 0 ) {
  2747.                if ( lines > 59 ) {
  2748.                   page += 1;
  2749.                   lines = top_of_page ( page, acct, FALSE );
  2750.                }
  2751.                Cprnout ( '\n' );
  2752.                for ( i=0; i<strlen(months[m]); Cprnout(months[m][i++]) );
  2753.                Cprnout ( '\r' );
  2754.                Cprnout ( '\n' );
  2755.                for ( i=0; i<78; Cprnout ( rule[i++] ) );
  2756.                Cprnout ( '\r' );
  2757.                Cprnout ( '\n' );
  2758.                lines += 3;
  2759.             }
  2760.             c = 0;
  2761.             while ( c<numtrans && !stop ) {
  2762.                fread ( &check[2], 1, 4, mfile );
  2763.                strncpy ( num, &check[2], 4 );
  2764.                num[4] = 0;
  2765.                fread ( &check[17], 1, 25, mfile );
  2766.                fread ( future_use, 1, 5, mfile );
  2767.                fread ( &check[44], 1, 25, mfile );
  2768.                fread ( future_use, 1, 5, mfile );
  2769.                fread ( &check[71], 1, 2, mfile );
  2770.                fread ( &check[74], 1, 2, mfile );
  2771.                fread ( &check[77], 1, 2, mfile );
  2772.                fread ( future_use, 1, 2, mfile );
  2773.                fread ( &amnt, 4, 1, mfile );
  2774.                sprintf ( amnt_str, "%ld.%02ld", amnt/100, amnt%100 );
  2775.                al = strlen ( amnt_str );
  2776.                for ( i=8; i<16-al; check[i++]=' ' );
  2777.                for ( i=0; i<al; ++i )
  2778.                   check[16-al+i] = amnt_str[i];
  2779.                fread ( &check[0], 1, 1, mfile );
  2780.                fread ( future_use, 1, 40, mfile );
  2781.                for ( i=0; i<79; Cprnout ( check[i++] ) );
  2782.                Cprnout ( '\r' );
  2783.                Cprnout ( '\n' );
  2784.                lines += 1;
  2785.                if ( strcmp ( num, "9999" ) == MATCH ) {
  2786.                   ++d_cnt;
  2787.                   d_tot += amnt;
  2788.                }
  2789.                else {
  2790.                   ++c_cnt;
  2791.                   c_tot += amnt;
  2792.                }
  2793.                if ( lines > 62 ) {
  2794.                   page += 1;
  2795.                   lines = top_of_page ( page, acct, FALSE );
  2796.                }
  2797.                if ( ( key_stat = Bconstat ( CONSOLE ) ) == CHAR_AVAIL )
  2798.                   if ( ( key = Bconin ( CONSOLE ) ) == ESCAPE )
  2799.                      stop = TRUE;
  2800.                ++c;
  2801.             }
  2802.          }
  2803.          fclose ( mfile );
  2804.          ++m;
  2805.       }
  2806.       if ( lines > 59 ) {
  2807.          page += 1;
  2808.          lines = top_of_page ( page, acct, FALSE );
  2809.       }
  2810.       print_totals ( c_cnt, d_cnt, c_tot, d_tot );
  2811.       Cprnout ( '\f' );
  2812.    }
  2813. }
  2814.  
  2815.  
  2816. print_totals ( c_cnt, d_cnt, c_tot, d_tot )
  2817. int c_cnt, d_cnt;
  2818. long c_tot, d_tot;
  2819. {
  2820.    int i;
  2821.    char s[20];
  2822.  
  2823.    Cprnout ( '\r' );
  2824.    Cprnout ( '\n' );
  2825.    for ( i=0; i<15; Cprnout ( ' ' ), ++i );
  2826.    strcpy ( s, "# of debits: " );
  2827.    for ( i=0; i<13; Cprnout ( s[i++] ) );
  2828.    sprintf ( s, "%d", c_cnt );
  2829.    for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) );
  2830.    for ( i=0; i<5; Cprnout ( ' ' ), ++i );
  2831.    strcpy ( s, "Total: $" );
  2832.    for ( i=0; i<8; Cprnout ( s[i++] ) );
  2833.    sprintf ( s, "%ld.%02ld", c_tot/100, c_tot%100 );
  2834.    for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) );
  2835.  
  2836.    Cprnout ( '\r' );
  2837.    Cprnout ( '\n' );
  2838.    for ( i=0; i<15; Cprnout ( ' ' ), ++i );
  2839.    strcpy ( s, "# of credits: " );
  2840.    for ( i=0; i<14; Cprnout ( s[i++] ) );
  2841.    sprintf ( s, "%d", d_cnt );
  2842.    for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) );
  2843.    for ( i=0; i<5; Cprnout ( ' ' ), ++i );
  2844.    strcpy ( s, "Total: $" );
  2845.    for ( i=0; i<8; Cprnout ( s[i++] ) );
  2846.    sprintf ( s, "%ld.%02ld", d_tot/100, d_tot%100 );
  2847.    for ( i=0; i<strlen ( s ); Cprnout ( s[i++] ) );
  2848. }
  2849.  
  2850.  
  2851. format_date ( d1, d2 )
  2852. char *d1, *d2;
  2853. {
  2854.    strcpy ( d1, d2 );
  2855.    d1[2] = '/';
  2856.    strcpy ( &d1[3], &d2[2] );
  2857.    d1[5] = '/';
  2858.    strcpy ( &d1[6], &d2[4] );
  2859. }
  2860.  
  2861.  
  2862. top_of_page ( page, acct, first_page )
  2863. int page, first_page;
  2864. char *acct;
  2865. {
  2866.  
  2867.    int i, len;
  2868.    char heading[80];
  2869.  
  2870.    if ( !first_page )
  2871.       Cprnout ( '\f' );
  2872.    Cprnout ( '\n' );
  2873.    Cprnout ( '\n' );
  2874.    for ( i=0; i<78; Cprnout( rule[i++]) );
  2875.    Cprnout ( '\r' );
  2876.    Cprnout ( '\n' );
  2877.    strcpy ( heading, "ACCOUNT:                                                                   " );
  2878.    strcpy ( &heading[9], acct );
  2879.    heading[strlen(heading)] = ' ';
  2880.    strcpy ( &heading[33], "DATE: " );
  2881.    strcpy ( &heading[39], date_but );
  2882.    heading[47] = ' ';
  2883.    strcpy ( &heading[68], "PAGE:  " );
  2884.    sprintf ( &heading[74], "%d", page );
  2885.    len = strlen (heading);
  2886.    for ( i=0; i<len; Cprnout(heading[i++]) );
  2887.    Cprnout ( '\r' );
  2888.    Cprnout ( '\n' );
  2889.    for ( i=0; i<78; Cprnout(rule[i++]) );
  2890.    Cprnout ( '\r' );
  2891.    Cprnout ( '\n' );
  2892.    Cprnout ( '\n' );
  2893.    return ( 6 );
  2894. }
  2895.  
  2896.  
  2897. do_new_year ()
  2898. {
  2899.   int choice, x, m, trans, cnt;
  2900.   int dial_x, dial_y, dial_w, dial_h;
  2901.   char s[64], mnth0[64];
  2902.   FILE *tfile;
  2903.   struct check tmpchk;
  2904.  
  2905.   choice = form_alert(2,"[2][WARNING! This function will|destroy existing MicroCheck|files!| |Do you want to continue?][YES|NO]");
  2906.   if ( choice == YES ) {
  2907.     choice = form_alert(2,"[2][Are you absolutely sure that|you want to begin a new year?| ][YES|NO]");
  2908.     if ( choice == YES ) {
  2909.        cnt = 0;
  2910.        choice = get_acct ();
  2911.        if ( choice ) {
  2912.           if ( ( tfile = fopen ( "TEMP.DAT", "bw" ) ) == 0 )
  2913.             form_alert ( 1, "[1][Cannot open file!|New Year abandoned.][OK]" );
  2914.           else {
  2915.             fwrite ( &cnt, 2, 1, tfile );
  2916.             form_center ( lkmndial_addr, &dial_x, &dial_y, &dial_w, &dial_h );
  2917.             form_dial ( FMD_START, 0, 0, 10, 10, dial_x, dial_y, dial_w, dial_h );
  2918.             string = get_tedinfo_str ( lkmndial_addr, SCANMNTH );
  2919.             strcpy ( string, "         " );
  2920.             objc_draw ( lkmndial_addr, 0, 8, dial_x, dial_y, dial_w, dial_h );
  2921.             for ( x=0; x<13; ++x ) {
  2922.               strcpy ( s, filename );
  2923.               sprintf ( &s[strlen(s)-4], "%d", x );
  2924.               strcpy ( &s[strlen(s)], ".DAT" );
  2925.               if ( x==0 )
  2926.                 strcpy ( mnth0, s );
  2927.               if ( ( mfile = fopen ( s, "br" ) ) == 0 )
  2928.                 form_alert ( 1, "[1][Cannot open monthly files!|New Year abandoned.][OK]" );
  2929.               else {
  2930.                 strcpy ( string, months[x] );
  2931.                 objc_draw ( lkmndial_addr, SCANMNTH, 8, 
  2932.                             dial_x, dial_y, dial_w, dial_h );
  2933.                 fread ( &trans, 2, 1, mfile );
  2934.                 for ( m=0; m<trans; ++m ) {
  2935.                   fread ( tmpchk.number, 1, 4, mfile );
  2936.                   fread ( tmpchk.payee, 1, 30, mfile );
  2937.                   fread ( tmpchk.memo, 1, 30, mfile );
  2938.                   fread ( tmpchk.date, 1, 8, mfile );
  2939.                   fread ( &tmpchk.amount, 4, 1, mfile );
  2940.                   fread ( tmpchk.cancel, 1, 1, mfile );
  2941.                   fread ( future_use, 1, 40, mfile );
  2942.                   if ( tmpchk.cancel[0] == ' ' ) {
  2943.                     fwrite ( tmpchk.number, 1, 4, tfile );
  2944.                     fwrite ( tmpchk.payee, 1, 30, tfile );
  2945.                     fwrite ( tmpchk.memo, 1, 30, tfile );
  2946.                     fwrite ( tmpchk.date, 1, 8, tfile );
  2947.                     fwrite ( &tmpchk.amount, 4, 1, tfile );
  2948.                     fwrite ( tmpchk.cancel, 1, 1, tfile );
  2949.                     fwrite ( "THIS SPACE FOR POSSIBLE FUTURE EXPANSION", 1, 40, tfile );
  2950.                     cnt += 1;
  2951.                   }
  2952.                 }
  2953.                 if ( fclose ( mfile ) != 0 )
  2954.                   form_alert ( 1, "[1][File close error!][OK]");
  2955.                 mfile = fopen ( s, "bw" );
  2956.                 fwrite ( &zero, 2, 1, mfile );
  2957.                 fclose ( mfile );
  2958.               }
  2959.             }
  2960.             rewind ( tfile );
  2961.             fwrite ( &cnt, 2, 1, tfile );
  2962.             if ( fclose ( tfile ) != 0 )
  2963.               form_alert ( 1, "[1][File close error!][OK]");
  2964.             Fdelete ( mnth0 );
  2965.             Frename ( zero, "TEMP.DAT", mnth0 );
  2966.           }
  2967.        }
  2968.     }
  2969.   }
  2970. }
  2971.  
  2972.  
  2973. make_upper_case ( string )
  2974. char *string;
  2975. {
  2976.    int x;
  2977.  
  2978.    for ( x=0; x<strlen(string); ++x )
  2979.       string[x] = toupper ( string[x] );
  2980. }
  2981.  
  2982.  
  2983. no_decimal ( s )
  2984. char *s;
  2985. {
  2986.    int x, i, d, len;
  2987.    char s2[20], s3[20];
  2988.  
  2989.    strcpy ( s2, s );
  2990.    len = strlen ( s2 );
  2991.    i = 0;
  2992.    d = FALSE;
  2993.    for ( x=0; x<len; ++x )
  2994.       if ( d && s2[x] != ' ' )
  2995.          ++i;
  2996.       else
  2997.          if ( s2[x] == ' ' )
  2998.             d = TRUE;
  2999.  
  3000.    if ( i == 0 && len < 6 )
  3001.       strcpy ( &s2[len], "00" );
  3002.    else
  3003.       if ( i == 1 || len == 6 )
  3004.          strcpy ( &s2[len], "0" );
  3005.  
  3006.    i = 0;
  3007.    for ( x=0; x<strlen(s2); ++x )
  3008.       if ( s2[x] != ' ' & s2[x] != '.' )
  3009.          s3[i++] = s2[x];
  3010.    s3[i] = 0;
  3011.    strcpy ( s, s3 );
  3012. }
  3013.  
  3014.  
  3015. long str_to_long ( s )
  3016. char *s;
  3017. {
  3018.    int x, len, factor;
  3019.    long num;
  3020.  
  3021.    num = 0;
  3022.    len = strlen ( s );
  3023.    factor = len - 1;
  3024.    for ( x=0; x<len; ++x )
  3025.       num += (long) ( s[x] - '0' ) * pwrs[factor--];
  3026.    return ( num );
  3027. }
  3028.  
  3029.